Very much I ask for help! I create a website, register and log in, everything seemed to work, but then, apparently, I accidentally changed something and now I get an error “OSError: [WinError 123] Syntax error in the file name, folder name or volume label: ””
If you rummage in the console above, where there is an enumeration of all files, you can find the line ModuleNotFoundError: No module named ‘first.apps.FirstConfig’; ‘first.apps’ is not a package. Probably there is a problem with it, but I can’t find it on my own.
Next, I will provide the files and folder locations
URLS (GENERAL)
import first
from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url, include
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
path ('', include ('first.urls')),
path ('rule', include ('first.urls')),
path ('admin /', admin.site.urls),
path ('grappelli /', include ('grappelli.urls')), # grappelli URLS
] + static (settings.STATIC_URL, document_root = settings.STATICFILES_DIRS)
URLS (LOCAL)
from django.urls import path
from. import views
import first
from django.conf.urls.static import static
from django.conf import settings
from django.conf.urls import include, url
from django.views.generic.edit import FormView
from django.contrib.auth.forms import UserCreationForm
urlpatterns = [
path ('reg', views.index, name = 'index'),
path ('rule', views.poop, name = 'poop'),
path ('register /', views.RegisterFormView.as_view ()),
path ('login /', views.LoginFormView.as_view ()),
path ('about', views.about, name = 'about'),
#url (r '^ register / $', views.RegisterFormView.as_view ()),
] + static (settings.STATIC_URL, document_root = settings.STATICFILES_DIRS)
VIEWS
from django.shortcuts import render
import first
from django.views.generic.edit import FormView
from django.contrib.auth.forms import UserCreationForm
# Again, thanks to django for the out-of-the-box authentication form.
from django.contrib.auth.forms import AuthenticationForm
# Function for setting the session key.
# This will tell django if the user is signed in.
from django.contrib.auth import login
class LoginFormView (FormView):
form_class = AuthenticationForm
# Similar to registration, only using the authentication template.
template_name = "first / login.html"
# If successful, we will redirect to the main page.
success_url = "/ about"
def form_valid (self, form):
# Get the user object based on the data entered into the form.
self.user = form.get_user ()
# Authenticate the user.
login (self.request, self.user)
return super (LoginFormView, self) .form_valid (form)
class RegisterFormView (FormView):
form_class = UserCreationForm
# Link to which the user will be redirected in case of successful registration.
# In this case, there is a link to the login page for registered users.
success_url = "/ login"
# The template to be used when rendering the view.
template_name = "first / registration.html"
def form_valid (self, form):
# Create a user if the data in the form was entered correctly.
form.save ()
# Call the base class method
return super (RegisterFormView, self) .form_valid (form)
def poop (request):
return render (request, 'first / rules.html')
def index (request):
return render (request, 'first / registration.html')
def about (request):
return render (request, 'first / about.html')
settings
Import First
Import OS.
Import sys
# Build Paths Inside The Project Like This: os.path.join (Base_Dir, ...)
Base_dir = os.path.dirname (os.path.abspath (__ File__)))
Project_ROot = OS.path.dirname (__ File__)
sys.path.insert (0, os.path.join (Project_Root, 'Apps'))
# Quick-Start Development Settings - Unsuitable For Production
# See https://docs.djangoproject.com/en/3.0/howto/Deployment/checklist/
# Security Warning: Don't Run With Debug Turned On In Production!
Debug = True.
Allowed_Hosts = []
# Application Definition
Installed_apps = [
'grapppelli',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'first.apps.firstconfig',
]
Authentication_backen = (
# Needed To Login by Username in Django Admin, Regardless of `Allauth`
'django.contrib.auth.backends.modelbackend',
# `Allauth` Specific Authentication Methods, Such As Login by E-mail
'allauth.account.auth_backen.authenticationBackend',
)
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',
]
Root_urlconf = 'universal.urls'
TEMPLATES = [
{
'Backend': 'django.demplate.backends.django.djangoteplates',
'Dirs': [
os.path.join (Project_Root, 'Templates'),
],
'App_Dirs': True,
'Options': {
'context_processors': [
'django.template.context_processors.request',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.ath.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
Wsgi_application = 'universal.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#Databases.
Databases = {
'Default': {
'Engine': 'django.db.backends.sqlite3',
'Name': os.path.join (Base_Dir, 'db.sqlite3'),
}
}
# Password Validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-Validators
Auth_password_validators = [
{
'Name': 'django.contrib.auth.password_validation.userattributeSimilarityValidator',
},
{
'Name': 'django.contrib.auth.password_validation.minimumlengthvalidator',
},
{
'Name': 'django.contrib.auth.password_validation.comMonpasswordValidator',
},
{
'Name': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# INTERNATIONALIZATION
# https://docs.djangoproject.com/en/3.0/topics/i18n/
Language_code = 'RU'
Time_Zone = 'UTC'
Use_i18n = True.
Use_L10N = True.
Use_Tz = True.
# STATIC Files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
Static_url = '/ Static /'
Static_root = os.path.join (Base_Dir, "Static")
Media_root = os.path.join (Base_Dir, "Media")
Media_url = '/ media /'
Staticfiles_dirs = [
'Universal / Static',
]
Answer 1, Authority 100%
It turned out that the file apps.py was purified by some way
That’s what inscribed there:
from django.apps import appconfig
Class FirstConfig (AppConfig):
name = 'first'
Now everything works