我正在使用django-allauth
进行身份验证。我有一个有很多链接的仪表板。Django将数据从一个应用程序传递给另一个应用程序?
user.html
`{% include 'sidebar.html' %}
<h1>Profile View</h1>
<p>{{ profile.username }}</p>`
change_password.html
`{% include 'sidebar.html' %}
<h2>Change Password</h2>
<p>{{ profile.username }}</p>`
sidebar.html
`<a href="{% url 'profile_view' slug=profile.username %}">Profile View</a>
<a href="{% url 'change_password' %}">Change Password</a>`
views.py
class ProfileView(DetailView):
template_name = "user.html"
queryset = User.objects.all()
context_object_name = 'profile'
slug_field = "username"
改变密码视图是从Django的allauth。我如何将用户名从ProfileView
传递到更改密码视图,以便我可以在change_password.html
页面中显示。
主要问题 ,因为我已经得到了包括sidebar.html
双方的意见,它的工作好于ProfileView
但是当我浏览到change_password
观点,我收到以下错误
反向与关键字“profile_view”参数'{'slug':''}'找不到。 1个图案(多个)尝试:[ '(?P [ - \瓦特@ + - ] +)/ $']
误差不在ProfileView
显示因为profile.username
返回一个值,但是当我导航到change_password
视图我得到上述错误,因为profile
上下文对象只在该特定视图中传递。我想通过该项目使用该context_object。
有没有简单的方法来做到这一点?除了构建JSON API?
没了!那不是我正在寻找的..有没有其他方法可以做到这一点?可能从零开始写东西 – Rahul
嘿@Rahul,我不确定django-allauth在做什么,但通常用户信息通过'{{user}}或'{{request.user}}提供给每个视图' 。做那两项工作?如果没有,那么django-allauth正在为中间件做些什么。在这种情况下,您可以编写自定义模板标签以从allauth获取用户名。看到这里:https://docs.djangoproject.com/en/1.11/howto/custom-template-tags/ – teewuane
如果你想与一个手,让我知道。 – teewuane