i'm trying have tags return tags detail page getting following error message
i getting error "didn't return httpresponse object. returned none instead"
i tried copy , modify "post" class suit "tags" needs it's not working heres code
models.py:
class tag(models.model): title = models.charfield(max_length=250) slug = models.slugfield(max_length=200, unique=true) timestamp = models.datetimefield(auto_now=false, auto_now_add=true) updated = models.datetimefield(auto_now=true, auto_now_add=false) def __str__(self): return self.title def get_absolute_url(self): return reverse("posts:tag_index", kwargs={"slug": self.slug}) class meta: ordering = ["-timestamp"]
my posts/urls.py:
from django.conf.urls import url .views import post_list, post_create, post_detail, post_update, post_delete, sewp, tagindex urlpatterns = [ url(r'^$', post_list, name='list'), url(r'^tag/(?p<slug>[\w-]+)/$', tagindex, name="tag_index"), url(r'^create/$', post_create, name='create'), url(r'^sewp$', sewp, name='sewp'), url(r'^(?p<slug>[\w-]+)/$', post_detail, name='detail'), url(r'^(?p<slug>[\w-]+)/edit/$', post_update, name='update'), url(r'^(?p<id>\d+)/delete/$', post_delete, name='delete'), ]
my views.py:
def tagindex(request, slug=none): instance = get_object_or_404(tag, slug=slug) context = { "instance": instance } render(request, "posts/tags.html", context)
my tags.html:
{% extends 'posts/base.html' %} {% block content %} {{ instance }} {% endblock content %}
i saw video on youtube the guy did
def detail(request): message = "hello" return httpresponse(message)
but doesn't suit needs. how can make when click link posts same link shown on tags.html page?
you should return render
return render(request, "posts/tags.html", context)
render shortcut rendering template context , returning httpresponse
Comments
Post a Comment