The error im getting is
django.core.exceptions.ImproperlyConfigured: The included URLconf 'buttonpython.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
I am following an older django tutorial because those are literally all i can find and got his error. Here is the urls.py:
from . import views
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.button)
]
Settings.py (i included this because i found the buttonpython.urls variable in it):
INSTALLED_APPS = [
'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 = 'buttonpython.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['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 = 'buttonpython.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/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/2.2/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/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
Views.py:
from django.shortcuts import render
from . import urls.py
import requests
from bs4 import BeautifulSoup
def button(request):
return render(request, 'home.html')
def output(request):
def trade_spider(max_pages):
page = 1
data = ''
while(page <= max_pages):
search = 'Ipad'
url = 'https://www.ebay.com/sch/i.html?_from=R40&_nkw=' + search + '&_sacat=0&_pgn=' + str(page)
src = requests.get(url)
text = src.text
soup = BeautifulSoup(text, features="html.parser")
for link in soup.findAll('a', {'class': 's-item__link'}):
href = link.get('href')
title = link.string
if(title == None):
title = "Sorry the title was unavailable however you can check the price."
price = get_item_price(href)
data += href + '\n' + title + '\n' + price + '\n'
page+=1
return data
def get_item_price(item_url):
src = requests.get(item_url)
text = src.text
soup = BeautifulSoup(text, features="html.parser")
for item_price in soup.findAll('span', {'class': 'notranslate'}):
price = item_price.string
return price
data = trade_spider(1)
return render(request, 'home.html', {'data':data})
I am stumped any help would be appreciated.
As the error says, you have a circular import. For some reason your views.py is importing urls.py. There is no reason to do that, you should remove that import.
start project:
django-admin.py startproject buttonpython
cd buttonpython
start app:
django-admin.py startapp app_name
settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app_name',
]
app_name/views.py
same as your views.py
in your question. without import urls.py
.
urls.py:
from app_name import views
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.button, name="home")
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.