fix: article creation
This commit is contained in:
@@ -70,4 +70,8 @@ form {
|
|||||||
|
|
||||||
.text {
|
.text {
|
||||||
min-height: 500px;
|
min-height: 500px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
color: red;
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,9 @@
|
|||||||
<textarea class="text" name="text" placeholder="Текст статьи">{{ form.text }}</textarea>
|
<textarea class="text" name="text" placeholder="Текст статьи">{{ form.text }}</textarea>
|
||||||
<input class="submit" type="submit" value="Сохранить">
|
<input class="submit" type="submit" value="Сохранить">
|
||||||
</form>
|
</form>
|
||||||
{{ form.errors }}
|
<div class="error">
|
||||||
|
{{ error }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p><a href="/">← Назад к списку статей</a></p>
|
<p><a href="/">← Назад к списку статей</a></p>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -19,11 +19,14 @@ def create_post(request):
|
|||||||
'text': request.POST["text"], 'title': request.POST["title"]
|
'text': request.POST["text"], 'title': request.POST["title"]
|
||||||
}
|
}
|
||||||
if form["text"] and form["title"]:
|
if form["text"] and form["title"]:
|
||||||
|
print('try')
|
||||||
try:
|
try:
|
||||||
article = Article.objects.create(text=form["text"], title=form["title"], author=request.user)
|
article = Article.objects.create(text=form["text"], title=form["title"], author=request.user)
|
||||||
return redirect('get_article', article_id=article.id)
|
return redirect('get_article', article_id=article.id)
|
||||||
except:
|
except:
|
||||||
return render(request, 'article_invalid_name.html')
|
return render(request, 'article_invalid_name.html')
|
||||||
|
else:
|
||||||
|
return render(request, 'new_article.html', {'form': form, 'error': 'Введите название и текст статьи!'})
|
||||||
|
|
||||||
if not request.user.is_anonymous:
|
if not request.user.is_anonymous:
|
||||||
return render(request, 'new_article.html')
|
return render(request, 'new_article.html')
|
||||||
|
|||||||
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Reference in New Issue
Block a user