Ric*_*ard 4 django django-urls
我想用另外一种 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'}))
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用,因为我没有patterns正确使用该对象:我明白了AttributeError at /robots.txt - 'tuple' object has no attribute 'resolve'.
我怎样才能在Django中正确执行此操作?
试试这个:
if settings.IS_PRODUCTION:
additional_settings = patterns('',
(r'^robots\.txt$', direct_to_template, {'template': 'robots_production.txt', 'mimetype': 'text/plain'}),
)
else:
additional_settings = patterns('',
(r'^robots\.txt$', direct_to_template, {'template': 'robots_dev.txt', 'mimetype': 'text/plain'}),
)
urlpatterns += additional_settings
Run Code Online (Sandbox Code Playgroud)
由于您希望追加tuple类型,append不起作用.
另外,pattern()打电话urlresolver给你.在你的情况下,你不是,因此错误.
| 归档时间: |
|
| 查看次数: |
4917 次 |
| 最近记录: |