“如何使用Django Usurena”;“照片”;模板变量
我试图在我们的Django网站中使用Userena,但我似乎不知道如何使用模板标签来显示照片。我尝试了以下方法在图像标记中吐出URL:“如何使用Django Usurena”;“照片”;模板变量,django,django-templates,Django,Django Templates,我试图在我们的Django网站中使用Userena,但我似乎不知道如何使用模板标签来显示照片。我尝试了以下方法在图像标记中吐出URL: <img src="{{ owner_profile.get_mugshot_url }}"> 及 有人有什么见解吗 谢谢 使用以下代码在模板中显示Userena个人资料图像(mugshot)。使用适当的用户名筛选所需的用户 视图.py from django.shortcuts import get_object_or_404
<img src="{{ owner_profile.get_mugshot_url }}">
及
有人有什么见解吗
谢谢 使用以下代码在模板中显示Userena个人资料图像(mugshot)。使用适当的用户名筛选所需的用户 视图.py
from django.shortcuts import get_object_or_404
from django.contrib.auth.models import User
def my_view(request):
profile = get_object_or_404(User, username__iexact=username).get_profile()
return render_to_response('template.html', locals(), context_instance=RequestContext(request))
在这里,我将这个变量“profile”呈现给模板“template.html”。在模板中包含以下代码以显示mugshot图像
template.html
<img src="{{ profile.get_mugshot_url }}" />
这对我有用。希望它也能对你有用。谢谢。使用以下代码在模板中显示Userena个人资料图像(mugshot)。使用适当的用户名筛选所需的用户 视图.py
from django.shortcuts import get_object_or_404
from django.contrib.auth.models import User
def my_view(request):
profile = get_object_or_404(User, username__iexact=username).get_profile()
return render_to_response('template.html', locals(), context_instance=RequestContext(request))
在这里,我将这个变量“profile”呈现给模板“template.html”。在模板中包含以下代码以显示mugshot图像
template.html
<img src="{{ profile.get_mugshot_url }}" />
这对我有用。希望它也能对你有用。谢谢。试试这个:
{{ user.get_profile.get_mugshot_url }}
试试这个:
{{ user.get_profile.get_mugshot_url }}
根据alican的回答,只需在模板中添加以下代码:
<img src="{{ user.get_profile.get_mugshot_url }}" />
根据alican的回答,只需在模板中添加以下代码:
<img src="{{ user.get_profile.get_mugshot_url }}" />
以下是我的工作方式:
{{user.get\u profile.get\u mugshot\u url}
但是,请确保对将要导入的每个页面(例如:views.py)使用render
,而不是render\u to\u response
:
从django.shortcuts导入渲染
return render(请求'sometemplate.html',{“name”:“some_var”},)
我是这样做的,在navbar下拉菜单(例如:sometemplate.html)中插入了面部照片:
{%if user.u经过身份验证%}
-
{%else%}
{%endif%}
以下是我的工作方式:
{{user.get\u profile.get\u mugshot\u url}
但是,请确保对将要导入的每个页面(例如:views.py)使用render
,而不是render\u to\u response
:
从django.shortcuts导入渲染
return render(请求'sometemplate.html',{“name”:“some_var”},)
我是这样做的,在navbar下拉菜单(例如:sometemplate.html)中插入了面部照片:
{%if user.u经过身份验证%}
-
{%else%}
{%endif%}
我不确定Userna是什么,但除非您明确地将概要文件
传递给模板上下文,否则它将不可用。如果你已经实现了标准的django配置文件
,你可以通过user.get\u profile.foo
访问它,假设auth
context\u处理器
已经添加到模板\u context\u处理器
中,谢谢Yuji-我没有将“配置文件”传递给模板。。。菜鸟的错误,我知道;)谢谢。我不确定Userna是什么,但是除非你已经明确地将profile
传递给你的模板上下文,否则它将不可用。如果你已经实现了标准的django配置文件
,你可以通过user.get\u profile.foo
访问它,假设auth
context\u处理器
已经添加到模板\u context\u处理器
中,谢谢Yuji-我没有将“配置文件”传递给模板。。。菜鸟的错误,我知道;)谢谢。您如何获得用户的视图?从userena或django身份验证后端?更清楚地解释它们,以便更好地理解。如何让用户进入视图?从userena或django身份验证后端?更清楚地解释,以便更好地理解。