How to use the Django Usurena “mugshot” template variable

前端 未结 4 1574
名媛妹妹
名媛妹妹 2021-01-21 21:44

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

相关标签:
4条回答
  • 2021-01-21 22:25

    Try this:

    {{ user.get_profile.get_mugshot_url }}
    
    0 讨论(0)
  • 2021-01-21 22:31

    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>
    
    0 讨论(0)
  • 2021-01-21 22:35

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

    <img src="{{ user.get_profile.get_mugshot_url }}" />
    
    0 讨论(0)
  • 2021-01-21 22:35

    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.

    0 讨论(0)
提交回复
热议问题