Я получаю сообщение об ошибке, хотя я настроил DJANGO_SETTINGS_MODULES соответствующим образом.
Ошибка: django .core.exceptions.ImproperlyConfigured: запрошенный параметр INSTALLED_APPS, но параметры не настроены. Вы должны либо определить переменную среды DJANGO_SETTINGS_MODULE, либо вызвать settings.configure () перед доступом к настройкам. Вот мой views.py :
import requests
from bs4 import BeautifulSoup
from django.shortcuts import redirect, render
from django.shortcuts import render
from django.http import HttpResponse
import os
from models import *
requests.packages.urllib3.disable_warnings()
def index(request):
session=request.Session()
session.headers={"User-Agent":"Googlebot/2.1 (+http://www.google.com/bot.html)"}
url="https://weather.com/en-IN/weather/today/l/9d531fc505eb4a93a90a7e8303ccaa22a142c9370b68391129de5019ee7adf5b"
content=session.get(url,verify=False).content
soup=BeautifulSoup(content,"html.parser")
for hit in soup.findAll(attrs={'class':'today_nowcard-temp'}):
head=hit.text
summ=(hit.next_sibling.text)
weather=News()
weather.header=head
weather.summary=summ
print(head)
print(summ)
weather.save()
return redirect("../")
def news_list(request):
weathers=News.objects.all()
context={
'object_list': weathers,
}
return render(request,'index.html',context)
This is settings.py:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'th9v0%i9^#4a30t3bn*0w_1qm9ci&(8q%xd*q+&*h1amyr77j9'
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'news.apps.NewsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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 = 'Learn.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'Learn.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'News',
'USER':'postgres',
'PASSWORD':'gateexam',
'HOST':'localhost'
}
}
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',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
STATICFILES_DIRS=[
os.path.join(BASE_DIR,'static'),
]
STATIC_ROOT=os.path.join(BASE_DIR,'assets')
MEDIA_URL='/media/'
MEDIA_ROOT=os.path.join(BASE_DIR,'media')
This is models.py:
from django.db import models
class News(models.Model):
header=models.CharField(max_length=100)
summary=models.CharField(max_length=100)[![enter image description here][1]][1]
def __str__(self):
return self.header
Ниже мое рабочее пространство :
Другое приложение cal c работает без ошибок.