I get this error when I run python manage.py - python

So I am working with Django. After setting up my URLs in both applications, I get this error when I run python manage.py migrate:
"file "C:\Users\Eric\Anaconda3\envs\myDjangoEnv\lib\site
packages\django\urls\resolvers.py", line 542, in url_patterns raise
ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf 'alerts.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".
However, when I comment out include in my alerts.urls file it works fine. How can I fix this? I have attached my urls.py files.
This is my accounts.urls file:
from django.urls import path from django.contrib.auth import views as auth_views from . import views
app_name = 'accounts'
urlpatterns = [
path('login/',auth_views.LoginView.as_view(template_name='accounts/login.html'), name ='login'),
path('logout/', auth_views.LogoutView.as_view(), name ='logout'),
path('signup/', views.SignUp.as_view(), name ='signup'),
]
This is my main alerts urls.py file:
from django.contrib import admin
from django.urls import include,path
from django.urls import path,include from . import views
urlpatterns = [
path('', views.HomePage.as_view(), name="home"),
path('admin/', admin.site.urls),
path('test/', views.TestPage.as_view(), name="test"),
path('thanks/', views.ThanksPage.as_view(), name="thanks"),
path('accounts/', include("accounts.urls", namespace="accounts")),
path('accounts/', include("django.contrib.auth.urls")),
]

Related

Running Django Server

I need help tried to run server for Django and got this error, The included URLconf '<module 'myapp.urls' from 'C:\Users\user\Documents\Django Tutorial\myproject\myapp\urls.py'>' does not appear to have any patterns in it. If you see the 'urlpatterns' variable with valid patterns in the file then the issue is probably caused by a circular import.
for urls.py in myproject is:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myapp.urls')),
]
for myapp views.py is:
from django.shortcuts import render
from django.http import HttpResponse
def index(request): return HttpResponse('hello')
For myapp urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]

Error message in Django when I try to runserver - does not appear to have any patterns in it. If you s ee valid patterns in the

Every time I write python manage.py run server. I get the error message:
The included URLconf '<module 'strana.views' from 'D:\\novi projekat\\strana\\views.py'>' 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.
mysite urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('strana/', include('strana.views')),
]
myapp(named strana)
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
views.py
from django.http import HttpResponse
def index(request):
return HttpResponse('Kita u Bila')
You included your views module. You want to include the module that contains your urls.
from django.contrib import admin from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('strana/', include('strana.urls')),
]

I have an error in my Django accounts app

I was following the tutorial on https://simpleisbetterthancomplex.com/series/2017/09/25/a-complete-beginners-guide-to-django-part-4.html and I have an error message which says that account_views is not defined. In my urls.py file which is located in C:\Users\vitorfs\Development\myproject\myproject\myproject. Here is the code
from django.conf.urls import url
from django.contrib import admin
from accounts import views as account_views
from boards import views
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^signup/$', accounts_views.signup, name='signup'),
url(r'^boards/(?P<pk>\d+)/$', views.board_topics, name='board_topics'),
url(r'^boards/(?P<pk>\d+)/new/$', views.new_topic, name='new_topic'),
url(r'^admin/', admin.site.urls),
]
The error is on line 25, url(r'^signup/$', accounts_views.signup, name='signup'), which states that account_views is not defined. I would like to know why I am getting this error, and also, can you show me how to fix this error?
When you are importing the accounts in the top of the file, you are saying from accounts import views as account_views. You are importing it as account_views so in your urls, you should say account_views not accounts_views.

django 2.2.5 import url from one app to another app

I would like to use the url from products app (products/urls.py) inside of search app url (search/urls.py) to search for items/products using search bar. I've attempted this example on django docs but it's importing a view to url in the same app, and I've also attempted this example but it looks to be a solution for an older version of django but i am using the latest version of django at time time 2.2.5.
The error message I am receiving in terminal is coming from search/urls.py:
path('', views.ProductListView.as_view(), name='list'),
AttributeError: module 'search.views' has no attribute
'ProductListView'
I understand search.views does not have an attribute "ProductListView" but, products.views does, which is why i'm trying to import products.views in search/urls.py.
products/urls.py
from django.urls import path, re_path
from .import views
app_name = "products"
urlpatterns = [
path('', views.ProductListView.as_view(), name='list'),
re_path(r'^products/(?P<slug>[\w-]+)/$', views.ProductDetailSlugView.as_view(), name='detail'),
]
search/urls.py
from django.urls import path
from .import views
from products.views import ProductListView
urlpatterns = [
path('', views.ProductListView.as_view(), name='list'),
]
ecommerce/urls.py (main app)
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include, re_path
# from products.views import ProductDetailView
from .views import home, about, contact
urlpatterns = [
path('admin/', admin.site.urls),
path('', home, name='home'),
path('about/', about, name='about'),
path('contact/', contact, name='contact'),
path('account/', include('allauth.urls'), name='login'),
path('register/', include('allauth.urls'), name='register'),
path('products/', include('products.urls', namespace='products')),
path('search/', include('search.urls', namespace='search')),
# path('', include('products.urls'), name='products-featured'),
# path('', include('products.urls'), name='featured-details'),
# path('', include('products.urls'), name='featured-slug-details'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
You have:
from products.views import ProductListView
Therefore you should use ProductListView, not views.ProductListView
urlpatterns = [
path('', ProductListView.as_view(), name='list'),
...
]
Note you can remove the from .import views import unless you are using views somewhere else in search/urls.py
An alternative is to use import as, so that you can import multiple views.py from different apps in the same module:
from products import views as product_views
urlpatterns = [
path('', product_views.ProductListView.as_view(), name='list'),
]

Django-url cmd server error

from django.contrib import admin
from django.urls import path
from adoptions import views
urlpatterns = [
path('admin/', admin.site.urls),
path(r'^$', views.home name='home'),
path(r'^adoptions/(\d+)/', views.pet_detail, name='pet_detail'),
]
this is my code when I run python manage.py runserver...
It returns a syntax error.. saying third line in urlpatterns "name" error which is (name='home') here..

Categories