[Django]添加robots.txt

方法一 : 可以直接在程序中添加url映射

在最外层的urls.py中添加

1
2
3
4
5
urlpatterns  =  patterns('',
       ......
      (r '^robots\.txt$' lambda  r: HttpResponse( "User-agent: *\nDisallow: /" , mimetype = "text/plain" )),
      (r '^CCSN\.txt$' lambda  r: HttpResponse( "CCWSN00210" , mimetype = "text/plain" )),
)


这里是比较懒省事的方法,直接返回了response,也可以使用渲染模板的方式。


方法二: 如果使用的是nginx部署可以在,nginx -uwsgi配置文件中添加url映射

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
server {
         listen   80 ;
         server_name  127.0 . 0.1 ;
         location  / robots.txt {
           root   html;
         }
 
         location  / CCSN.txt {
           root   html;
         }
         location  /  {
             uwsgi_pass    127.0 . 0.1 : 9090 ;
             include     uwsgi_params;
             access_log  off;
         }
  }

 root 目录指的是nginx下html目录,就是放置nginx自带的index.html那个目录

nginx 配置重启

 /usr/local/nginx/sbin/nginx -t

 /usr/local/nginx/sbin/nginx -s reload


你可能感兴趣的:(Django,如今Python)