python - Problam with views and template in Django - show data in template -
I have a problam in Django. I am a beautiful Django developer. I can not show my "category" data in the template here The code is: models.py
Import TaggableManager category category (models.Model) from Django DB import module with taggit.members: Title = models.CharField (max_length = 40) def __unicode __ (self): return self. Title class post (Model. Model): Title = Model. Kharifild (max_length = 150) body = models.TextField () date = Model DataTimeField () Tags = TagGalemanager () Cats = Model. Myatomyfield (category) def __unicode__ (auto): Return to SevTital
views.py urls.py Pre> This is my category.html Thanks.
. Models post, category urlpatterns = pattern ('blog.views', url (r '^ $', ListView.as_view (queryset = Post.objects.as). By Order ("- Date") []:], Template_name = "index.html"), url (r) '^ (? P & lt; pk & gt; \ d +) $', detailView.as_view (model = post, template_name = "post.html")), a part of url (r ^ template "post.html"
#some html code here {% include "category.html"%} # and some HTML code here
Your way of writing code is considerations for a fairly backend code, urls.py only URL The specifications are for those who do not have to write questions.
views.py
Import range from blog to blog.models. Model Import Post
DF Cats (Request): queryset = Post.objects.all () Order_by ("- date") [: 2] Return to render_to_response ('category.html', {'queryset': queryset}, Context_instance = RequestContext (request))
Add url (r '^ cats', 'blog.views.cats') = = 'cats')
In the category .html
You can view.py (here queryset
)
& lt; Li & gt; & Lt; A href = "#" & gt; {{Querset.title}} & lt; / A & gt; & Lt; / Li & gt;
Comments
Post a Comment