Изучаю джанго по видеоурокам и столкнулся с проблемой. См сабж
Код формы:
from .models import Articles
from django.forms import ModelForm, TextInput, DateTimeInput, Textarea
class ArticlesForm(ModelForm):
class Meta:
Model = Articles
fields = ['title', 'anons', 'full_text', 'date']
widgets = {
'title': TextInput(attrs={
'class': 'form-control',
'placeholder': 'Название статьи'
}),
'anons': TextInput(attrs={
'class': 'form-control',
'placeholder': 'Анонс статьи'
}),
'date': DateTimeInput(attrs={
'class': 'form-control',
'placeholder': 'Дата публикации'
}),
'full_text': Textarea(attrs={
'class': 'form-control',
'placeholder': 'Текст статьи'
})
}
код views
from django.shortcuts import render
from .models import Articles
from .forms import ArticlesForm
def news_home(request):
news = Articles.objects.all()
return render(request, 'news/news_home.html', {'news': news})
def create(request):
Form = ArticlesForm()
data = {
'form': Form
}
return render(request, 'news/create.html', data)
HTML код
{% extends 'main/layout.html' %}
{% block title %}Форма добавления статьи{% endblock %}
{% block content %}
<div class='features'>
<h1>Форма добавления статьи</h1>
<form method="post">
{% csrf_token %}
{{ form.title }}<br>
{{ form.anons }}<br>
{{ form.full_text }}<br>
{{ form.date }}<br>
<button class="btn btn-success" type="submit">Добавить статью</button>
</form>
</div>
{% endblock %}
Ошибка
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/news/create
Django Version: 4.0.1
Python Version: 3.9.5
Installed Applications:
['main',
'news',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "C:\Users\***\PycharmProjects\jango\venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\***\PycharmProjects\jango\venv\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\***\PycharmProjects\jango\firstpj\news\views.py", line 10, in create
Form = ArticlesForm()
File "C:\Users\***\PycharmProjects\jango\venv\lib\site-packages\django\forms\models.py", line 293, in __init__
raise ValueError('ModelForm has no model class specified.')
Exception Type: ValueError at /news/create
Exception Value: ModelForm has no model class specified.