How to use the Django Usurena “mugshot” template variable

ⅰ亾dé卋堺 提交于 2019-12-02 05:23:20

问题


I'm trying to use Userena in our Django website, but I can't seem to figure out how to use the template tag to display the mugshot. I have tried the following to spit out the URL within an image tag:

<img src="{{ owner_profile.get_mugshot_url }}">

and

<img src="{{ profile.get_mugshot_url }}">

Anyone have some insight??

Thanks!


回答1:


based on alican answer, just put following code in your template:

<img src="{{ user.get_profile.get_mugshot_url }}" />



回答2:


Use the following code to display Userena profile image(mugshot) in your template. Use appropriate username to filter the required user.

views.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))

Here I have rendered this variable "profile" to the template "template.html". Include following code in your template to display mugshot image.

template.html

    <img src="{{ profile.get_mugshot_url }}" />

It worked for me. Hope it will work for you too. Thanks.




回答3:


Try this:

{{ user.get_profile.get_mugshot_url }}



回答4:


Here's the way it worked for me:

{{ user.get_profile.get_mugshot_url }}

But make sure you use render as opposed to render_to_response for each of the pages that you'll be pulling it in (ex: views.py):

from django.shortcuts import render

return render(request, 'sometemplate.html', {"name": "some_var"}, )

Here's how I did it, pulling in the mugshot for the navbar dropdown (ex: sometemplate.html):

<ul class="nav pull-right">
    {% if user.is_authenticated %}
        <li class="dropdown">
          <a href="#" class="dropdown-toggle user-dropdown" data-toggle="dropdown">
            <img class="user-thumbnail img-circle" src="{{ user.get_profile.get_mugshot_url }}" alt="" />
            Hi, {{ user.username }}
            <b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="{% url 'userena_profile_detail' user.username %}"><i class="icon-wrench"></i> Profile</a></li>
              <li class="divider"></li>
              <li><a href="/accounts/signout"><i class="icon-off"></i> Log Out</a></li>
            </ul>
        </li>
    {% else %}
        <li><a href="/accounts/signin">Log in</a></li>  
    {% endif %}
</ul>


来源:https://stackoverflow.com/questions/9102968/how-to-use-the-django-usurena-mugshot-template-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!