App error . Attribute error with first application - django

I have created this app in django but i cannot access the app . CMD says
Attribute error : module 'hello.views' has no attribute 'index'
VIEWS.PY
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse('Hello World !!!')
URLS.PY/admin
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('hello.urls'))
]
URLS.PY/Hello
from django.urls import path
from . import views
urlpatterns = [
path('hello/', views.index, name='index')
]

You need to put commas after path().
path('hello/', views.index, name='index'), # Very important comma.
I think you missed one in each file.
I now see the other problem. Change your hello.urls.py path to
path('',
Your current configuration is looking for
/hello/hello/
If you put that in your browser it might work.

Related

You are seeing this page because DEBUG=True is in your settings file and you have not configured any URLs

the explorer in vscode Getting the error: You are seeing this page because DEBUG=True is in your settings file and you have not configured any URLs.
meetups/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('meetups/', views.index) #domain_name.com/meetups/
]
urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('meetups.urls'))
]
views.py
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request,'templates/meetups/index.html')
You probably didn't add your app (meetups) into settings.INSTALLED_APPS, which can be found in your_project_name/settings.py.
Change meetups/templates/index.html to meetups/index.html also add name in your urlpatterns

DetailView Django dont work error page not found

When I click on the article I get
How can I fix it?
I tried url, path and other but I have this error
urls.py
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('index', include('mainpage.urls')),
path('blog', include('news.urls')),
path('games', include('games.urls')),
path('fortnite', include('fortnite.urls')),
path('contacts', include('contact.urls')),
path('admin', admin.site.urls),
]
news/urls.py
from django.urls import path,include,re_path
from django.conf.urls import url
from . import views
from django.views.generic import ListView, DetailView
from news.models import Articles
urlpatterns = [
path('', ListView.as_view(queryset=Articles.objects.all().order_by('-date')[:20],template_name='news.html')),
path('<int:pk>/', DetailView.as_view(model=Articles, template_name='news/post.html'))
]
First of all please add '/' at end of all your path strings , change it like this
path('index/', include('mainpage.urls')),
path('blog/', include('news.urls')),
path('games/', include('games.urls')),
path('fortnite/', include('fortnite.urls')),
path('contacts/', include('contact.urls')),
path('admin/', admin.site.urls),
]
check if it works or not

Error while using URLconf defined in mysite.urls (Django tutorial)

I know this question has been asked and i have gone through all those answers but i didn't get the solution still. Please help me find out what is wrong .
This is the code from django website for version 1.11 of django .
mysite/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
mysite/polls/urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
mysite/polls/views.py
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
I am getting the following error
Click to view the error
Your urls.py is in the wrong place, it should be mysite/mysite/urls.py (in the same directory as settings.py).

AttributeError: module 'calc.views' has no attribute 'home'

I know there are some questions asked already but none of worked for me
server is not running with the command throwing this error
calc urls.py
from django.urls import path
from . import views
urlpatterns = [
path('',views.home, name='home')
]
calc views.py
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello World !")
saish urls.py
from django.contrib import admin
from django.urls import path , include
urlpatterns = [
path('', include('calc.urls')),
path('admin/', admin.site.urls),
]

How to fix 'The included URLconf 'gp.urls' does not appear to have any patterns in it'

when i tried to write the first urlpattern and the first view, i got this error, so i can be able to access to the authentification template, i have no idea what can be the source of this error
# my gp/urls.py
from django.contrib import admin
from django.conf.urls import url
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^$', views.index, name='index'),
]
# my views.py
from django.shortcuts import render
def index(request):
return render(request,'gp/index.html')
when i try to run the server this is the error i get
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf
'gp.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.
this is my program tree
gp
apps
conge
organisation
personnel
stage
gp
pycache
init.py
settings.py
urls.py
views.py
wsgi.py
static
templates
gp
index.html
db.sqlte3
manage.py
# my gp/urls.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index, name='index'),
]
# my views.py
from django.shortcuts import render
def index(request):
return render(request,'gp/index.html', {})
what i edited is:
instead of from django.conf.urls import url i wrote from
django.urls import path
added {} in render function (its optional but just in case :) )
As stated in here: https://code.djangoproject.com/ticket/30728#no1
Maybe try to use latest Python version. Python 3.9 able to work