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')
]
Related
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'),
]
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
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 was trying to call one html file from another via Django.
I actually have no errors inside my project(It works). But when I am trying to call the second html file the page refreshes only. Here is my code, thanks:D. My projects name is information and the name of my app is basic.
basic.views.py:
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request,'basic/index.html')
def customer(request):
return render(request,'basic/customer.html')
basic.urls.py:
from django.urls import path
from basic import views
app_name='basic'
urlpatterns=[
path('',views.index,name='index'),
path('',views.customer,name='customer'),
]
information.urls.py:
from django.contrib import admin
from django.urls import path,include
from basic import views
urlpatterns = [
path('',views.index,name="index"),
path('admin/', admin.site.urls),
path('',include('basic.urls'))
]
The problem is that you have two paths that match exactly the same path. So that means each time you make a request with an empty path, the first one is used.
You should make use of non-overlapping paths, for example:
# basic/urls.py
from django.urls import path
from basic import views
app_name='basic'
urlpatterns=[
path('', views.index, name='index'),
path('customer/', views.customer, name='customer'),
]
and in your information/urls.py:
# information/urls.py
from django.contrib import admin
from django.urls import path,include
from basic import views
urlpatterns = [
path('', views.index, name='index'),
path('admin/', admin.site.urls),
path('basic/', include('basic.urls'))
]
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")),