regex - NoReverseMatch within a template action url -
i have url in main urlconf:
url(r'^confirm-invite/(?p<token>[\w-]+)/$', confirm_invite, name="confirm_invite_page"),
this (wip version) view hooked to:
def confirm_invite(req, token): template_name = 'invites/confirm_invite.html' if req.method == 'post': form = activationform(req.post) if form.is_valid(): try: auth_user = authenticate(username=user.username, password=form.cleaned_data['activation_code']) except: homecoming httpresponse('didnt authenticate') if auth_user none: homecoming httpresponse('auth_user none') login(req, auth_user) homecoming httpresponse('you activated account') else: homecoming httpresponse('form error foo') else: invite = get_object_or_404(invite, token=token) user = invite.user if user.is_active == true: homecoming httpresponse('user active') else: form = activationform() homecoming render(req, template_name, {'form': form})
and here snippet of html:
<form action="{% url 'confirm_invite_page' token %}" method="post">{% csrf_token %} {{form.as_p}} <input type="submit" value="activate"> </form>
for reason reverse url in html, {% url 'confirm_invite_page' token %}
, throwing out matching problems
here total traceback:
traceback: file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 114. response = wrapped_callback(request, *callback_args, **callback_kwargs) file "/users/nir/nirla/nirla/apps/invites/views.py" in confirm_invite 78. homecoming render(req, template_name, {'form': form}) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/shortcuts/__init__.py" in render 53. homecoming httpresponse(loader.render_to_string(*args, **kwargs), file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/loader.py" in render_to_string 169. homecoming t.render(context_instance) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/base.py" in render 140. homecoming self._render(context) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/base.py" in _render 134. homecoming self.nodelist.render(context) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/base.py" in render 840. bit = self.render_node(node, context) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/debug.py" in render_node 78. homecoming node.render(context) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/loader_tags.py" in render 123. homecoming compiled_parent._render(context) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/base.py" in _render 134. homecoming self.nodelist.render(context) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/base.py" in render 840. bit = self.render_node(node, context) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/debug.py" in render_node 78. homecoming node.render(context) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/loader_tags.py" in render 62. result = block.nodelist.render(context) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/base.py" in render 840. bit = self.render_node(node, context) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/debug.py" in render_node 78. homecoming node.render(context) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/defaulttags.py" in render 447. six.reraise(*exc_info) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/template/defaulttags.py" in render 433. url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse 532. homecoming iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) file "/users/nir/nirla/venv/lib/python2.7/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix 452. (lookup_view_s, args, kwargs, len(patterns), patterns)) exception type: noreversematch @ /confirm-invite/6f0ce05c8404470bb996f20c8271e363/ exception value: reverse 'confirm_invite_page' arguments '('',)' , keyword arguments '{}' not found. 1 pattern(s) tried: ['confirm-invite/(?p<token>[\\w-]+)/$']
i thought set correctly considering docs, problem match?
you need alter lastly line to
return render(req, template_name, {'form': form, 'token': token})
because otherwise, template not have variable.
regex django django-forms django-templates django-urls
No comments:
Post a Comment