python - Adding two IDs to my urls dispatcher -



python - Adding two IDs to my urls dispatcher -

i'm relatively new python/django. i'm having issue sending ids through urls.py.

i trying add together admin business profile page in project.

my views.py:

@login_required def make_admin(request, bus_id, user_id): user = request.user u = get_object_or_404(user, pk = user_id) b = get_object_or_404(business, pk = bus_id) b.admin.add(u) followcount = b.followers.count() photo = businesslogo.objects.all().filter(business_link = bus_id)[:1] homecoming render_to_response('business/followers.html', {'user':user, 'b':b, 'followcount':followcount, 'photo':photo, 'u':u}, context_instance=requestcontext(request))

in template trying pass bus_id user_id maintain getting syntax error, assuming related urls.

my template:

... {% if follow in b.admin.all %} [<a href="{% url remove_admin b.id u.id %}">remove admin</a>] {% else %} [<a href="{% url make_admin b.id u.id %}">make admin</a>] {% endif %} ...

my urls.py @ moment:

url(r"^make/(?p<bus_id>\d+)/(?p<user_id>\d+)/$", make_admin, name="make_admin"), url(r"^remove/(?p<bus_id>\d+)/(?p<user_id>\d+)/$", remove_admin, name="remove_admin"),

i having hard time figuring out how add together user_id urls. above illustration not work.

thanks everyone,

steve

edit: error im presented is:

caught noreversematch while rendering: reverse 'remove_admin' arguments '(1l, '')' , keyword arguments '{}' not found.

the thing can see seems wrong {% if follow in b.admin.all %} there's no follow variable in context in code posted.

if posted more details of error, or stack trace, helpful.

edit: ok, error helpful :)

caught noreversematch while rendering: reverse 'remove_admin' arguments '(1l, '')' , keyword arguments '{}' not found.

this means url reversal function got 2 arguments 1l , ''. 1l integer 1 python long integer, '' means passed in none or blank string.

since called url reversal in template {% url remove_admin b.id u.id %} sec argument value of u.id. check value of u variable, seems not have valid id attribute, it's not expect (i'd guess it's not user object @ all)

python django django-models django-templates django-views

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -