path('',include('personal.urls')),
^
SyntaxError: invalid syntax
When I run the server using python manage.py runserver for the following code I got this error.
url patterns
from django.contrib import admin
from django.urls import include
from django.conf.urls import url
from django.urls import path
#from django.conf.urls import url
#from django.urls import path
urlpatterns = [
url('admin/', admin.site.urls)
path('',include('personal.urls')),
]
url patterns for my app 'personal'
from django.urls import include
from django.conf.urls import url
from django.urls import path
from . import views
#import URLs
urlpatterns = [
path('', views.index, name='index'),
]
This is views.py code
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request,'personal/home.html')
It's the comma after the first line. Replace with this:
urlpatterns = [
url('admin/', admin.site.urls),
path('',include('personal.urls')),
]
It might be due to missing namespace. Try to include the namespace in your main.urls.
path('', include('personal.urls', namespace="personal")),
Related
thats my app urls
from django.urls import path
from . import views
urlpatterns = [
path('', views.tasklist, name='tasks'),
]
thats my projects urls
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('list.urls')),
]
thats views urls
from django.shortcuts import render
from django.http import HttpResponse
def tasklist(request):
return HttpResponse('TO DO List')
I tried a lot of things but none of them worked
you have to add your app into INSTALLED_APPS list in settings.py
I am trying to simply put a 'Hello World' text on the server. And it brings an error.
Project Urls.py :
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myapp.urls'))
]
App Urls.py
from django.urls import path
from . import views
urlpattern = [
path('', views.index,name = 'index')
]
Views.py
from django.shortcuts import render
from django.http import HttpResponse
def index(response):
return HttpResponse('<h1>Hello World</h1>')
The Error it tells me:
The included URLconf in myapp/urls.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.
You are missing an 's' in your apps urls.py.
it has to be 'urlpatterns', instead of 'urlpattern'
urlpatterns = [
path('', views.index,name = 'index')
]
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 am a newcomer and I wrote Hello Word to start practicing and I use Django==3.1
and python3 and I encountered this error: ImportError: cannot import name 'home_page' from 'shop.views'
views.py
from django.shortcuts import render
from django.http import HttpResponse
def home_page(request):
return HttpResponse('Hello world')
urls.py
from django.contrib import admin
from django.urls import path
from .views import home_page
urlpatterns = [
path('admin/', admin.site.urls),
path('',home_page),
]
You should add your app_label to the import as well. from {app_name}.views import home_page
This should work fine for you
from django.contrib import admin
from django.urls import path
from django.urls.conf import include
from . import views
path('', Home.as_view(), name='home'),
You may also consider, path('', views.home),
** urls.py:-**
from django.contrib import admin
from django.urls import path
from {app_name}.views import home_page
urlpatterns = [
path('admin/', admin.site.urls),
path('',home_page,name='....'),
]
In 3rd line you need to add your app name inside {app_name}....
*from django.urls import path, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('products/',include('products.urls')),
path('accounts/',include('accounts.urls')),
]*
The above code of pyshop/url.py
I could not login to admin page.
from django.urls import path
from . import views
urlpatterns = [
path('', views.index),
path('products/new',views.new),
path('products/',views.products),
path('accounts/register',views.register),
]
The code is of product/urls.py.
Old question, but I run into the same problem, so just in case I can help someone else.
I would put in the pyshop/url.py, this code (see the admin path is the only one with an actual url):
from django.urls import path, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('products.urls')),
path('',include('accounts.urls')),
]
Then in your product/urls.py (See all of the routes end with a slash):
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name="product"),
path('products/new/',views.new, name="new_product"),
path('products/',views.products, name="products"),
path('accounts/register/',views.register, name="register"),
]