【发布时间】:2013-06-11 06:42:21
【问题描述】:
我想使用不同的robots.txt 文件,具体取决于我的服务器是生产服务器还是开发服务器。
为此,我想在urls.py 中以不同的方式路由请求:
urlpatterns = patterns('',
// usual patterns here
)
if settings.IS_PRODUCTION:
urlpatterns.append((r'^robots\.txt$', direct_to_template, {'template': 'robots_production.txt', 'mimetype': 'text/plain'}))
else:
urlpatterns.append((r'^robots\.txt$', direct_to_template, {'template': 'robots_dev.txt', 'mimetype': 'text/plain'}))
但是,这不起作用,因为我没有正确使用patterns 对象:我得到AttributeError at /robots.txt - 'tuple' object has no attribute 'resolve'。
如何在 Django 中正确执行此操作?
【问题讨论】:
标签: django django-urls