LoginSignup
7

More than 5 years have passed since last update.

Djangoでrobots.txt設置

Posted at

やりたいこと

http://example.com/robots.txt アクセスに対してrobos.txtを正しく返す。

手順

app_dir/urls.py にrobots.txtのルーティング記述

from django.views.generic import TemplateView

urlpatterns = [
    ...
    url(r'^robots\.txt', TemplateView.as_view(template_name='static/robots.txt', content_type='text/plain')),  # <- append

urls.pyの記述に対応するパスにrobots.txt を作成

template/static/robots.txt

(例はすべてのクローラー拒否)

User-agent: * 
Disallow: /

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7