Python/Django错误:"myapp"不是注册的名称空间 [英] Python/django error: 'myapp' is not a registered namespace
问题描述
我面临一个非常不寻常的问题.
I am facing a very unusual problem.
我已经在主项目的urls.py
文件中使用app_name
注册了名称空间myapp
,如下所示:
I've registered the namespace myapp
using app_name
in my main project's urls.py
file like this:
app_name = 'myapp'
我正在写一个视图,供用户注册并重定向到主页.但是,当我在myapp的views.py
文件中使用重定向功能时,如下所示:
I'm writing a view where the user registers and is redirected to the homepage. However, when I'm using the redirect function in myapp's views.py
file like this:
return redirect('myapp: index')
单击注册表单的提交"按钮后出现以下错误:
I'm getting the following error after clicking the registration form's submit button:
NoReverseMatch at /
'myapp' is not a registered namespace
我厌倦了寻找解决方案,但无济于事.请帮助:)
I tired looking for a solution but to no avail. Help please :)
推荐答案
app_name = 'myapp'
用于放置包含在中 urls.py
中.在另一个未包含的urls.py
中无效.
我建议将URL移入应用程序并将其包含在站点的urls.py
中.然后您的名称空间就可以工作.
I recommend moving your URLs into the app and including them in your site's urls.py
. Then your namespace should work.
这篇关于Python/Django错误:"myapp"不是注册的名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!