0

newbie django question

I'm using django-profiles to display a list of profiles, using profiles.views.profile_list view, and individual profiles, using profiles.views.profile_detail.

For each individual profile, I wanted to add a link to edit the profile, only if the profile corresponds to the current user. My first attempt was:

(...)
{% block content %}
<p>Profile detail info for {{ user }} </p>
<ul>
    <li>{{ user.username }}

        {% if user.is_authenticated %}
        <a href="{% url profiles_edit_profile user.username %}">edit</a>
        {% endif %}

    </li>
    <li>{{ user.get_profile.url }}</li> (...)

But then I hit the obvious issue: edit_profile is meant to edit the current user profile, so doesn't take username/ id as arguments, and django cannot reverse the url, because in fact I don't have a url to edit a named user's profile.

What's the best strategy here? copy the profiles app into my project and add the named user edit profile view? Or is there a way to do it without having to have a local project copy of the app - which I guess would be preferable?

thanks

1 Answer 1

0

The edit_profile view already enforces that the profile being edited is the current user's profile. You don't need to pass any arguments to it:

(...)
{% block content %}
<p>Profile detail info for {{ user }} </p>
<ul>
    <li>{{ user.username }}

        {% if user.is_authenticated %}
        <a href="{% url profiles_edit_profile %}">edit</a>
        {% endif %}

    </li>
    <li>{{ user.get_profile.url }}</li> (...)
1
  • yes that's right, thanks, I didn't think it through properly :)
    – xuloChavez
    Nov 8, 2011 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.