无法访问ros

2024-05-16 09:29:50 发布

您现在位置:Python中文网/ 问答频道 /正文

版本:

  • Python语言5.1
  • 迪亚戈1.10
  • django罗塞塔0.7.13

The installation guide告诉您将以下内容添加到项目的settings.py

from django.conf import settings

if 'rosetta' in settings.INSTALLED_APPS:
    urlpatterns += patterns('',
        url(r'^rosetta/', include('rosetta.urls')),
    )

但是,这只会导致错误:

^{pr2}$

Tags: the项目djangoinfrompyimport版本
1条回答
网友
1楼 · 发布于 2024-05-16 09:29:50

搜索该问题会发现one apparently has to import it

from django.conf.urls import patterns

但还是不行。在

^{pr2}$

此函数was removed in django 1.10。但是,可以使用以下方法有条件地添加rosetta url:

from django.conf import settings

if 'rosetta' in settings.INSTALLED_APPS:
    urlpatterns.append(url(r'^rosetta/', include('rosetta.urls')))

但是,如果您试图通过url http://127.0.0.1:8000/rosetta/访问rosetta,您可能会惊讶地发现您仍然得到一个404 Page not found。在

因此,包含的模式似乎无法正常工作。但他们是。问题是,有一个隐藏的要求,即访问rosetta页面时必须登录(可能是使用staff/super用户?)。所以,只需转到http://127.0.0.1:8000/admin/,登录,然后再次转到rosetta url。现在它应该可以工作了。在

安装程序注意到了这一点,有点:

Because Rosetta requires write access to some of the files in your Django project, access to the application is restricted to the administrator user only (as defined in your project’s Admin interface)

如果您没有登录,它怎么知道您是管理员?它没有,而且显然它没有给出一个信息错误,而是完全忽略了rosetta的url。在

相关问题 更多 >