python - NoReverseMatch for Dynamic URLs Django Template -


in urls.py have set url editing post slug/edit

url(r'^(?p<slug>[\w-]+)/edit/$', post_update, name='update'), 

when calling href="{% url 'posts:update' %} template, following error:

noreversematch @ /posts/this-is-my-title-to-my-awesome-post/  reverse 'update' arguments '()' , keyword arguments '{}' not found. 1 pattern(s) tried: ['posts/(?p<slug>[\\w-]+)/edit/$'] 

it seems fail inherit slug post instance. (to clear posts:update called within post itself. have tried type out correct full url, reversematch fails find pattern altogether.

environment:   request method: request url: http://192.168.1.58:8800/posts/this-is-my-title-to-my-awesome-post/  django version: 1.9.7 python version: 3.5.1 installed applications: ['django.contrib.admin',  'django.contrib.auth',  'django.contrib.contenttypes',  'django.contrib.sessions',  'django.contrib.messages',  'django.contrib.staticfiles',  'crispy_forms',  'trumbowyg',  'flatpages',  'home',  'posts'] installed middleware: ['django.middleware.security.securitymiddleware',  'django.contrib.sessions.middleware.sessionmiddleware',  'django.middleware.common.commonmiddleware',  'django.middleware.csrf.csrfviewmiddleware',  'django.contrib.auth.middleware.authenticationmiddleware',  'django.contrib.auth.middleware.sessionauthenticationmiddleware',  'django.contrib.messages.middleware.messagemiddleware',  'django.middleware.clickjacking.xframeoptionsmiddleware']   template error: in template c:\users\kasper\onedrive\projects\personalwebsite\_home\trydjango19env\src\templates\post_detail.html, error @ line 10    reverse 'update' arguments '()' , keyword arguments '{}' not found. 1 pattern(s) tried: ['posts/(?p<slug>[\\w-]+)/edit/$']   1 : {% extends "base.html" %}    2 :     3 : {% block head_title %}{{ instance.title }} | {{ block.super }} {% endblock %}    4 :     5 :     6 :     7 :     8 : {% block admin %}    9 :   <li><a href="#"></a></li>    10 :   <li><a href=" {% url 'posts:update' %} "></a></li>    11 :   <li><a href="{% url 'admin:index' %}">a</a></li>    12 : {% endblock admin %}    13 :     14 :     15 :     16 : {% block content %}    17 :     18 : <!--featured image-->    19 : <div class="flex-center" style="height: auto;">    20 :   <div class="view overlay hm-white-slight">   traceback:  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\core\urlresolvers.py" in reverse   586.                 extra, resolver = resolver.namespace_dict[ns]  during handling of above exception ('trydjango19.posts'), exception occurred:  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\defaulttags.py" in render   507.                               current_app=current_app)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\core\urlresolvers.py" in reverse   596.                                          key)  during handling of above exception ('trydjango19.posts' not registered namespace), exception occurred:  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\core\handlers\base.py" in get_response   149.                     response = self.process_exception_by_middleware(e, request)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\core\handlers\base.py" in get_response   147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)  file "c:\users\kasper\onedrive\projects\personalwebsite\_home\trydjango19env\src\posts\views.py" in post_detail   44.   return render(request, "post_detail.html", context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\shortcuts.py" in render   67.             template_name, context, request=request, using=using)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\loader.py" in render_to_string   97.         return template.render(context, request)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\backends\django.py" in render   95.             return self.template.render(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\base.py" in render   206.                     return self._render(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\base.py" in _render   197.         return self.nodelist.render(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\base.py" in render   992.                 bit = node.render_annotated(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\base.py" in render_annotated   959.             return self.render(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\loader_tags.py" in render   173.         return compiled_parent._render(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\base.py" in _render   197.         return self.nodelist.render(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\base.py" in render   992.                 bit = node.render_annotated(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\base.py" in render_annotated   959.             return self.render(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\defaulttags.py" in render   326.                 return nodelist.render(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\base.py" in render   992.                 bit = node.render_annotated(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\base.py" in render_annotated   959.             return self.render(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\loader_tags.py" in render   69.                 result = block.nodelist.render(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\base.py" in render   992.                 bit = node.render_annotated(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\base.py" in render_annotated   959.             return self.render(context)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\defaulttags.py" in render   513.                         six.reraise(*exc_info)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\utils\six.py" in reraise   686.         raise value  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\template\defaulttags.py" in render   499.             url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\core\urlresolvers.py" in reverse   600.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))  file "c:\users\kasper\onedrive\projects\person~1\_home\trydja~1\lib\site-packages\django\core\urlresolvers.py" in _reverse_with_prefix   508.                              (lookup_view_s, args, kwargs, len(patterns), patterns))  exception type: noreversematch @ /posts/this-is-my-title-to-my-awesome-post/ exception value: reverse 'update' arguments '()' , keyword arguments '{}' not found. 1 pattern(s) tried: ['posts/(?p<slug>[\\w-]+)/edit/$'] 

you missing object's slug:

href="{% url 'posts:update' 'object-slug-here' %} 

you can see options print url using django's url template tag.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -