This repository has been archived on 2023-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
python-blog/articles/views/api.py

22 lines
810 B
Python
Raw Normal View History

2020-12-29 13:16:54 +01:00
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.shortcuts import render
from django.views.decorators.http import require_POST
from articles.models import Article
@login_required
@require_POST
def render_article(request, article_pk):
template = "articles/article_detail.html"
article = Article.objects.get(pk=article_pk)
article.content = request.POST.get("content", article.content)
article.title = request.POST.get("title", article.title)
article.custom_css = request.POST.get("custom_css", article.custom_css)
has_code = request.POST.get("has_code")
if has_code is not None:
article.has_code = has_code == "true"
2020-12-29 13:16:54 +01:00
html = render(request, template, context={"article": article})
return HttpResponse(html)