Python/Django错误:"myapp"不是注册的名称空间 [英] Python/django error: 'myapp' is not a registered namespace

查看:334
本文介绍了Python/Django错误:"myapp"不是注册的名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临一个非常不寻常的问题.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆