Browse Source

Добавлен bootstrap и форма для статьи #15

pull/32/head
Artur Galyamov 2 years ago
parent
commit
dec7fb9af8
  1. 10
      cms/forms.py
  2. 2
      cms/models.py
  3. 41
      cms/templates/articles/new.html
  4. 15
      cms/templates/base.html
  5. 14
      cms/views.py
  6. 5
      crossposting_backend/settings.py

10
cms/forms.py

@ -1,5 +1,9 @@
from django.forms import ModelForm
from django import forms
from .models import Article
class ArticleForm(ModelForm):
pass
class ArticleForm(forms.ModelForm):
class Meta:
model = Article
fields = ('body', 'link',)

2
cms/models.py

@ -3,4 +3,4 @@ from django.db import models
class Article(models.Model):
body = models.TextField()
link = models.CharField(max_length=100, default='https://zakonvremeni.ru/news/')
link = models.CharField(max_length=300, default='https://zakonvremeni.ru/news/')

41
cms/templates/articles/new.html

@ -1,13 +1,28 @@
<h1>Заполните данные статьи для продвижения в соц. сетях</h1>
<form
method="post"
enctype="application/x-www-form-urlencoded"
action="{% url 'create-article' %}"
>
{% csrf_token %}
<label for="body">Краткий текст статьи</label>
<textarea id="body" name="body"></textarea>
<label for="link">Ссылка</label>
<input type="text" name="link" id="link">
<input type="submit" value="Продвинуть">
</form>
{% extends 'base.html' %}
{% load bootstrap5 %}
{% block content %}
<div class="container">
<div class="row my-5">
<div class="col-md-12">
<h1>Заполните данные статьи для продвижения в соц. сетях</h1>
<form
method="post"
enctype="application/x-www-form-urlencoded"
action="{% url 'create-article' %}"
class="form"
>
{% csrf_token %}
{% bootstrap_form new_article_form %}
{% buttons %}
<button
class="btn btn-primary"
type="submit"
>
Продвинуть
</button>
{% endbuttons %}
</form>
</div>
</div>
</div>
{% endblock content %}

15
cms/templates/base.html

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Продвижение новостей в соц. сетях</title>
{% load bootstrap5 %}
{% bootstrap_css %}
{% bootstrap_javascript %}
{% bootstrap_messages %}
</head>
<body>
{% block content %}
{% endblock content %}
</body>
</html>

14
cms/views.py

@ -1,14 +1,14 @@
import os
from json import JSONDecoder, JSONEncoder
from json import JSONEncoder
import requests
from django.http import JsonResponse, HttpRequest
from django.shortcuts import render
from django.utils.decorators import method_decorator
from django.views import View
from django.urls import reverse
from django.views.decorators.csrf import csrf_exempt
from cms.forms import ArticleForm
from cms.models import Article
@ -83,8 +83,10 @@ class ArticleView(View):
def new_article(request):
article_form = ArticleForm()
article_context = {
'new_article_form': article_form
}
return render(request,
template_name='articles/new.html',)
template_name='articles/new.html',
context=article_context)

5
crossposting_backend/settings.py

@ -41,7 +41,8 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'cms'
'cms',
'bootstrap5',
]
MIDDLEWARE = [
@ -59,7 +60,7 @@ ROOT_URLCONF = 'crossposting_backend.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [

Loading…
Cancel
Save