Q:

How can I add template view and the slug defining into one view? 

So I am working on some Django but kinda new to it.  I have this piece of code:
from django.shortcuts import render, render_to_response, get_object_or_404
from .models import Article
from django.views.generic import TemplateView

def view_post(request, slug):
    return render_to_response('news/article.html', {'post': get_object_or_404(Article, slug=slug)})

class ArticleView(TemplateView):
    template_name = "news/article.html"
    def get(self, request):
        article = Article.objects.all()
        return render(request, self.template_name ,{'article': article })

How can I write this into one view so I can use it in my urls.py? 
Right now this is my urls.py:
from django.conf.urls import url, include
from .views import view_post

urlpatterns = [
    url(r'^blog/view/(?P<slug>[^\.]+)', view_post , name='view_blog_post'),
]

How can I add them together?  Because I also want the variables to be available in my template. 

A:

I think this is what you want. 
class ArticleView(DetailView):
    query_pk_and_slug = 'slug'
    template_name = 'news/article.html'
    context_object_name = 'post'
    model = Article

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['article'] = Article.objects.all()
        return context

