I have followed the basic polls tutorial and I have tried to modify it to make it work for slugs but it's not working. I went from this in my views.py
def detail(request, article_id):
details = "blog/detail.html"
context = {
"article": get_object_or_404(Article, pk=article_id)
}
return render(request, details, context)
and
url(r'^(?P<article_id>[0-9]+)/$', views.detail, name='detail'),
to this in my views.py
def detail(request, slug):
details = "blog/detail.html"
context = {
"article": get_object_or_404(Article, slug)
}
return render(request, details, context)
and
url(r'^(?P<slug>[\w-]+)/$', views.detail, name='detail'),
this is my models.py
from django.db import models
from django.contrib.auth.models import User
class Article(models.Model):
author = models.ForeignKey(User)
title = models.CharField(max_length=250)
slug = models.SlugField()
body = models.TextField()
created = models.DateTimeField(auto_now=True)
def __str__(self):
return self.title
this is my admin.py
from django.contrib import admin
from .models import Article
@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("title",)}
but it's not working. How Do I get the slugs to show in my url