My url template not work
<p>I have a problem with my template tag url. The redirect not work when i click on button.</p>

<p>Django version => 1.9
Python version => 2.7</p>

<p>In my urls.py(main) i have:</p>

<pre><code>from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
from memoryposts.views import home, profile, preregistration

urlpatterns = [
    url(r'^$', home, name="home"),
    url(r'^grappelli/', include('grappelli.urls')),
    url(r'^admin/', admin.site.urls),
    url(r'^memory/', include("memoryposts.urls", namespace="memory")),
    url(r'^avatar/', include('avatar.urls')),
    url(r'^accounts/', include('registration.backends.hmac.urls')),
    url(r'^preregistration/', preregistration, name="preregistration"),
    url(r'^profile/', profile, name="profile"),
]

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
</code></pre>

<p>In my urls.py(apps) i have:</p>

<pre><code>from django.conf.urls import url
from django.contrib import admin
from .views import (
    memory_list,
    memory_create,
    memory_detail,
    memory_update,
    memory_delete,
)

urlpatterns = [
    url(r'^$', memory_list, name='list'),
    url(r'^create/$', memory_create, name='create'),
    url(r'^(?P&lt;slug&gt;[-\w]+)/$', memory_detail, name='detail'),
    url(r'^(?P&lt;slug&gt;[-\w]+)/edit/$', memory_update, name='update'),
    url(r'^(?P&lt;slug&gt;[-\w]+)/delete/$', memory_delete, name='delete'),
]
</code></pre>

<p>In my views.py(apps) i have:</p>

<pre><code>from django.contrib import messages
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, get_object_or_404, redirect
from .models import Post
from .forms import PostForm

def home(request):
    return render(request, "base.html")

def profile(request):
    return render(request, "profile.html")

def preregistration(request):
    return render(request, "preregistration.html")

def memory_create(request):

    form = PostForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        instance = form.save(commit=False)
        instance.save()
        messages.success(request,"SuccÃ¨s !")
        return HttpResponseRedirect(instance.get_absolute_url())
    context = {
        "form": form,
    }
    return render(request, "memory_create.html", context)

def memory_detail(request, slug=None):
    instance = get_object_or_404(Post, slug=slug)
    context = {
        "title":instance.title,
        "instance":instance,
    }
    return render(request, "memory_detail.html", context)

def memory_list(request):
    queryset = Post.objects.all()
    context = {
        "object_list": queryset,
    }
    return render(request, "memory_list.html", context)

def memory_update(request, slug=None):

        instance = get_object_or_404(Post, slug=slug)
        form = PostForm(request.POST or None, request.FILES or None, instance=instance)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.save()
            messages.success(request,"Mis Ã  jour !")
            return HttpResponseRedirect(instance.get_absolute_url())

        context = {
            "title":instance.title,
            "instance":instance,
            "form": form,
        }
        return render(request, "memory_create.html", context)

def memory_delete(request, slug=None):
    instance = get_object_or_404(Post, slug=slug)
    instance.delete()
    messages.success(request, "Supprimer !")
    return redirect("posts:list")
</code></pre>

<p>In my template html i have:</p>

<pre><code>&lt;button type="button" class="btn btn-primary"&gt;&lt;a id="back-profile" href="{% url 'memory:update' %}"&gt; Update&lt;/a&gt;&lt;/button&gt;

&lt;button type="button" class="btn btn-primary"&gt;&lt;a id="back-profile" href="{% url 'memory:delete' %}"&gt; Delete&lt;/a&gt;&lt;/button&gt;
</code></pre>

<p>The redirect not work with this template tag.
can you help me please :) ?</p>

<p>From doc here <a href="https://docs.djangoproject.com/en/1.10/topics/http/urls/#url-dispatcher" rel="nofollow">URL dispatcher</a></p>

<pre><code>&lt;button type="button" class="btn btn-primary"&gt;&lt;a id="back-profile" href="{% url 'memory:update' %}"&gt; Update&lt;/a&gt;&lt;/button&gt;

&lt;button type="button" class="btn btn-primary"&gt;&lt;a id="back-profile" href="{% url 'memory:delete' %}"&gt; Delete&lt;/a&gt;&lt;/button&gt;
</code></pre>

<p>You should put what you 'slug' in your button, like this (if slug is 200)</p>

<pre><code>&lt;button type="button" class="btn btn-primary"&gt;&lt;a id="back-profile" href="{% url 'memory:update' 200 %}"&gt; Update&lt;/a&gt;&lt;/button&gt;
</code></pre>

<p>Usually will look like this:</p>

<pre><code>{% for slug in slug_list %}
&lt;button type="button" class="btn btn-primary"&gt;&lt;a id="back-profile" href="{% url 'memory:update' slug %}"&gt; Update&lt;/a&gt;&lt;/button&gt;
{% endfor %}
</code></pre>

python django templates django-templates