fix: article creation

This commit is contained in:
root
2025-10-09 13:42:44 +03:00
parent 2c4f16ce60
commit a378414ea3
5 changed files with 11 additions and 1 deletions

View File

@@ -70,4 +70,8 @@ form {
.text {
min-height: 500px;
}
.error {
color: red;
}

View File

@@ -20,7 +20,9 @@
<textarea class="text" name="text" placeholder="Текст статьи">{{ form.text }}</textarea>
<input class="submit" type="submit" value="Сохранить">
</form>
{{ form.errors }}
<div class="error">
{{ error }}
</div>
</div>
<p><a href="/">← Назад к списку статей</a></p>
</body>

View File

@@ -19,11 +19,14 @@ def create_post(request):
'text': request.POST["text"], 'title': request.POST["title"]
}
if form["text"] and form["title"]:
print('try')
try:
article = Article.objects.create(text=form["text"], title=form["title"], author=request.user)
return redirect('get_article', article_id=article.id)
except:
return render(request, 'article_invalid_name.html')
else:
return render(request, 'new_article.html', {'form': form, 'error': 'Введите название и текст статьи!'})
if not request.user.is_anonymous:
return render(request, 'new_article.html')

Binary file not shown.

1
delete.sh Executable file
View File

@@ -0,0 +1 @@
sqlite3 db.sqlite3 < delete.sql