0
在urls.py我有以下註銷鏈接無法使用Django的
from django.conf.urls import url
from django.contrib.auth.views import logout
from core import views as core_views
urlpatterns = [
url(r'^logout/$', logout, {'template_name': 'core/logout.html'}, name='logout'),
url(r'^profile/$', core_views.view_profile, name = 'view_profile'),
etc...
]
我有一個包含每個頁面上base.html文件:
<!doctype html>
<head>
{% block head %}
<title>base</title>
{% endblock %}
</head>
<body>
<a href = 'core/logout.html'>Logout</a>
{% block body %}
{% endblock %}
</body>
</html>
的profile.html頁:
{% extends 'core/base.html' %}
{% block head %}
<title> Profile</title>
{% endblock %}
{% block body %}
<h2>Profile</h2>
<p>
{{ user.first_name }}<br/>
{{ user.last_name }}<br/>
{{ user.email }}<br/>
{{ user.userprofile.city }}
</p>
{% endblock %}
的logout.html頁:
{% extends 'core/base.html' %}
{% block head %}
<title>Logout</title>
{% endblock %}
{% block body %}
<p>Logged out</p>
{% endblock %}
問題是如果用戶在/配置文件並單擊頁面頂部的註銷鏈接,它將用戶發送到不存在的/ profile/logout,我如何獲取它以將用戶發送到/登出 ?
謝謝!多簡單的解決方案 –