Django-url cmd server error - python

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..

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')),
]

Page not found Error in my Django Project

I just started learning Django and got the following error:
[![The site doesn't see URL and then Error 404][1]][1]
urls.py - site
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('webexample/', include ('webexample.urls')),
]
urls.py - webexample
from django.urls import path
from . import views
urlpatterns = [
path(r'^$', views.index, name='index'),
]
views.py - webexample
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("<h3>This page isn't set up yet...</h3>")
Error photo
change path to this to work for the current url.
path(r'', views.index, name='index')
You could do this
path('index/', views.index, name='index'),
or
re_path(r'^index/$', views.index, name='index'),
to know more about this, you can the django doc https://docs.djangoproject.com/en/3.0/ref/urls/

very unexpected IndentationError: unexpected indent in django urls.py

This is urls.py for django project here all things are fine:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
]
but when I add my app url:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('movie/', include('movie.urls')),
]
it says
File "/storage/emulated/0/netflix/movie/urls.py", line 5
urlpatterns = [
^
IndentationError: unexpected indent
urlpatterns = [
path('index/', views.index, name='main-view'),]
try using name or relaunch the server

I get this error when I run python manage.py

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")),
]

Categories