Sanket
0
Q:

django detailview

##### views.py ######
from .models import Article
from django.views.generic import DetailView

class ArticleDetailView(DetailView):
    model = Article
    template_name = 'articles/article_detail.html'
    context_object_name = 'article' # name that will be used in .html view tmplate
    
##### urls.py (urlpatterns list) ######
path('articles/<int:pk>/', ArticleDetailView.as_view()),# pk is default slug (Primary key or id field in a model)
3
from django.views.generic.detail import DetailView
1
from django.views.generic import ListView
from books.models import Publisher

class PublisherList(ListView):
    model = Publisher
    context_object_name = 'my_favorite_publishers'
1
# The pk for the model is automatically applied to the url path.
class YourView(DetailView):
	model			= YourModel
    template_name	= 'your_template.html'
0

New to Communities?

Join the community