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

@@ -71,3 +71,7 @@ form {
.text { .text {
min-height: 500px; min-height: 500px;
} }
.error {
color: red;
}

View File

@@ -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>

View File

@@ -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')

Binary file not shown.

1
delete.sh Executable file
View File

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