I'm trying to use the class based views to create a page where I can delete an article by his ID.
here is the codes to create the pages where I can delete my articles.
views.py
class DeleteView(View):
def post(self, request, *args, **kwargs):
article = get_object_or_404(id=request.POST['article_id'])
article.delete()
return HttpResponseRedirect('/')
template.html
<form action="views.article.DeleteView" method="POST">
{% csrf_token %}
<p>{{ article.views.id }}"</p>
<input type="submit" value="Delete">
</form>
urls.py
url(r'^delete/(?P<id>\d+)/$', DeleteView.as_view(), name="DeleteView"),
Here is my problem > the page is not rendering, I'm getting a blank page without anything on it, how can I fix this?
******* EDIT *******
views.py
class DeleteView(View):
def post(self, request, *args, **kwargs):
article = get_object_or_404(id=request.POST['article_id'])
article.delete()
return HttpResponseRedirect('/')
def get(self, request, *args, **kwargs):
article = Article.objects.get(id=kwargs['id'])
context = {"article": article}
return render_to_response("template.html", context, context_instance=RequestContext(request))
Edit in template file:
Pleas, read this. The template file should end with
html
, notpy
.