Last active
October 7, 2015 09:27
-
-
Save sneeu/3142821 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.shortcuts import get_object_or_404, render | |
| from articles.forms import ArticleForm | |
| from articles.models import Article | |
| def article_edit(request, article_id): | |
| article = get_object_or_404(Article, pk=article_id) | |
| if request.method == 'POST': | |
| form = ArticleForm(request.POST, instance=article) | |
| if form.is_valid(): | |
| form.save() | |
| return redirect('article_detail', article_id=article.pk) | |
| else: | |
| form = ArticleForm(instance=article) | |
| context = { | |
| 'article': article, | |
| 'form': form, | |
| } | |
| return render(request, 'articles/article_edit.html', context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment