Stakha
Stakha

Reputation: 61

Django : multi variables in urls.py not working

I'm trying to construct a URL with two variables in a template, yet I just get the same error message. I'm quite new to Django, so I need your help :)

Exception Type: NoReverseMatch
Exception Value: Reverse for 'skill_update' with arguments '()' and keyword
arguments '{u'instancepk': 1, u'skillpk': 15}' not found. 1 pattern(s) 
tried: [u'persomaker/skill/update/(?P<skillpk>[0-9]+)$/(?P<instancepk>[0-9]+)$']

Template :

{% url 'persomaker:skill_update' skillpk=item.pk instancepk=instance.pk %}

view.py :

def skill_update(request,skillpk,instancepk):
    form = SkillCreateForm(request.POST)
    user = User.objects.get (id = request.user.id)
    instance = Character.objects.get (id = instancepk)
    if form.is_valid():
        form.save()
        return redirect('persomaker:skill_list', instance.id)
    else:
        skill = Skill.objects.get(id=pk)
        form = SkillCreateForm(initial={'character':instance})
        form.fields['skill'].widget = HiddenInput()
        form.fields['level'].queryset = range(0,7)
        form.fields['character'].widget = HiddenInput()
    return render(request, 'character/create_skill.html',
    {'instance':instance,
    'form': form,})

url.py :

url(r'^skill/update/(?P<skillpk>[0-9]+)$/(?P<instancepk>[0-9]+)$',
views.skill_update, name='skill_update'),

Upvotes: 0

Views: 53

Answers (2)

Exelian
Exelian

Reputation: 5888

You have 2 $ in the URL-config. That's not a valid regex since that assumes a newline.

Upvotes: 1

Daniel Roseman
Daniel Roseman

Reputation: 599590

You have a $ in the middle of your pattern regex. That's the terminating character; nothing after it will ever match. Remove the one in the middle.

Upvotes: 5

Related Questions