单击href Django时如何不附加/ home /

时间:2019-03-16 05:23:38

标签: django

如果我在网页public function destroy($id) { return view ('admin.tags.create'); /* Tag::destroy($id); Session::flash('success', 'Tag deleted succesfully'); return redirect()->back();*/ } 上,则在顶部有一个导航栏,该导航栏指向myapp.com/home。在我的delete_confirm.html页面中,该页面包含链接

home.html

这是我的<li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> User Settings </a> <div class="dropdown-menu" aria-labelledby="navbarDropdown"> <a class="dropdown-item" href="{% url 'delete_confirm_view' %)">Delete Account</a> </div> </li>

urls.py

还有urlpatterns = [ path('home/', home_view, name='home'), path('admin/', admin.site.urls, name='admin'), path('delete/', delete_user, name='delete'), url(r'^signup/$', views.signup, name='signup'), path('paste_list/', paste_list_view, name='paste_list'), url(r'^$', home_view), path('<str:custom_uuid>/edit', edit_view, name='edit_paste'), path('<str:custom_uuid>/', detail_view, name='detail'), path('accounts/', include('django.contrib.auth.urls')), path('delete_confirm_view/', delete_confirm_view, name="delete_confirm_view" ) ]

的相关部分
views.py

我得到的错误是:@login_required def delete_confirm_view(request): return render(request, "delete_confirm_view.html", {}) 我想知道如何不能包含附加到要检查的URL的The current path, home/{% url 'delete_confirm_view' %), didn't match any of these.部分。或者,如何正确地转到所需页面。

1 个答案:

答案 0 :(得分:0)

in your <project>/urls.py

from django.urls import path, include, re_path # url renamed as re_path in django2.0
from <your_app> import urls

urlpatterns = [
    path('', include("your_app.urls")), # probably, you are using `home` prefix here.
    path('admin/', admin.site.urls),
]