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): class Article(models.Model):
body = models.TextField() 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> {% extends 'base.html' %}
<form {% load bootstrap5 %}
method="post" {% block content %}
enctype="application/x-www-form-urlencoded" <div class="container">
action="{% url 'create-article' %}" <div class="row my-5">
> <div class="col-md-12">
{% csrf_token %} <h1>Заполните данные статьи для продвижения в соц. сетях</h1>
<label for="body">Краткий текст статьи</label> <form
<textarea id="body" name="body"></textarea> method="post"
<label for="link">Ссылка</label> enctype="application/x-www-form-urlencoded"
<input type="text" name="link" id="link"> action="{% url 'create-article' %}"
<input type="submit" value="Продвинуть"> class="form"
</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 import os
from json import JSONDecoder, JSONEncoder from json import JSONEncoder
import requests import requests
from django.http import JsonResponse, HttpRequest from django.http import JsonResponse, HttpRequest
from django.shortcuts import render from django.shortcuts import render
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views import View from django.views import View
from django.urls import reverse
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from cms.forms import ArticleForm
from cms.models import Article from cms.models import Article
@ -83,8 +83,10 @@ class ArticleView(View):
def new_article(request): def new_article(request):
article_form = ArticleForm()
article_context = {
'new_article_form': article_form
}
return render(request, 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.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'cms' 'cms',
'bootstrap5',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -59,7 +60,7 @@ ROOT_URLCONF = 'crossposting_backend.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [

Loading…
Cancel
Save