Python Url更改,但仍在同一页面上django
当我切换到“lostitems”页面时,它会成功显示,但当我切换到另一个页面“addlostitem”时,它仍然与以前在同一页面上,但url会改变我想要的方式 url.pyPython Url更改,但仍在同一页面上django,python,django,url,redirect,Python,Django,Url,Redirect,当我切换到“lostitems”页面时,它会成功显示,但当我切换到另一个页面“addlostitem”时,它仍然与以前在同一页面上,但url会改变我想要的方式 url.py url(r'lostitems/$', views.LostItemsView.as_view(), name='lost_items'), url(r'lostitems/addlostitems/$', views.RegisterLostView.as_view(), name='register_lost'), c
url(r'lostitems/$', views.LostItemsView.as_view(), name='lost_items'),
url(r'lostitems/addlostitems/$', views.RegisterLostView.as_view(), name='register_lost'),
class LostItemsView(generic.ListView):
model = Wallet
template_name = 'lostfound/lost_items.html'
class RegisterLostView(View):
model = Wallet
template_name = 'lostfound/register_lost.html'
视图.py
url(r'lostitems/$', views.LostItemsView.as_view(), name='lost_items'),
url(r'lostitems/addlostitems/$', views.RegisterLostView.as_view(), name='register_lost'),
class LostItemsView(generic.ListView):
model = Wallet
template_name = 'lostfound/lost_items.html'
class RegisterLostView(View):
model = Wallet
template_name = 'lostfound/register_lost.html'
这是因为您的URL模式(部分)与顺序中的第一个相匹配,因此应该解决以下问题:
url(r'^lostitems/$', views.LostItemsView.as_view(), name='lost_items'),
url(r'^lostitems/addlostitems/$', views.RegisterLostView.as_view(), name='register_lost'),
注意,我已经添加了
^
帽子登录,开始强制完全匹配 这是因为您的URL模式(部分)与顺序中的第一个匹配,因此应该解决以下问题:
url(r'^lostitems/$', views.LostItemsView.as_view(), name='lost_items'),
url(r'^lostitems/addlostitems/$', views.RegisterLostView.as_view(), name='register_lost'),
注意,我已经添加了
^
帽子登录,开始强制完全匹配 谢谢,当我添加“^”之后,它会变为另一个页面,但是页面现在是白色的,那么请检查您的register\u lost.html
,看看它是否正确地从base.html
(如果有)扩展并包含内容。在浏览器中检查页面的html源代码。我已经检查过了,它应该运行正常这是我的register_lost.html:{%extends'lostfound/base.html%}{%block title%}注册丢失的项目{%endblock%}{%block content%}{%load staticfiles%}你好{%endblock%}请选择您的lostfound/base.html
以及lostfound/register\u lost.html
(再次选择是)并共享链接。刚刚注意到为什么您的RegisterLostView
是从简单的视图扩展而来的,不是吗?它需要从FormView
或ListView
或TemplateView
或其他什么继承吗?谢谢,当我添加^,然后检查您的register\u lost.html
,看看它是否从base.html
(如果有的话)正确扩展并包含内容。在浏览器中检查页面的html源代码。我已经检查过了,它应该运行正常这是我的register_lost.html:{%extends'lostfound/base.html%}{%block title%}注册丢失的项目{%endblock%}{%block content%}{%load staticfiles%}你好{%endblock%}请您的lostfound/base.html
以及lostfound/register\u lost.html
(再次确认)并共享该链接。刚刚注意到为什么您的RegisterLostView
是从简单的视图扩展而来的,它不需要从FormView
或ListView
或TemplateView
等继承吗?