Добавлен bootstrap и форма для статьи #15
This commit is contained in:
parent
c4a41df849
commit
dec7fb9af8
10
cms/forms.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',)
|
||||
|
@ -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/')
|
||||
|
@ -1,13 +1,28 @@
|
||||
<h1>Заполните данные статьи для продвижения в соц. сетях</h1>
|
||||
<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 %}
|
||||
<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>
|
||||
{% 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
Normal file
15
cms/templates/base.html
Normal file
@ -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
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)
|
||||
|
@ -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…
x
Reference in New Issue
Block a user