Not Found: /hello/ - python

from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def index(request):
return HttpResponse("Hellow, World !")
from django.urls import path
from . import views
urlspattern=[
path("",views.index,name="index")
]
from django.contrib import admin
from django.urls import include,path
urlpatterns = [
path('admin/', admin.site.urls),
path("hello/", include("hello.urls"))
]
INSTALLED_APPS = [
'hello',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Error I am gettting is
Using the URLconf defined in helloproject.urls, Django tried these URL patterns, in this order:
admin/
The current path, hello/, didn't match any of these.

you have a typo error on urlpattern
urlspattern=[
path("",views.index,name="index")
]
you have to change that to
urlpatterns=[
path("",views.index,name="index")
]

In this line change urlpattern to urlpatterns
urlpatterns=[
path("",views.index,name="index")
]

Related

I followed the django example exactly. But it doesn't work

**
I followed the django example exactly. But it doesn't work. Web page just show the rocket to me.**
my project name: web
app name: main
web.settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
]
web.urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('main/', include('main.urls')),
path('admin/', admin.site.urls),
]
main.urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
main.views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
I hope web page shows "Hello, world. You're at the polls index." to me.
In your main urls file you have set:
urlpatterns = [
path('main/', include('main.urls')),
path('admin/', admin.site.urls),
]
Which actually means, that you need to go for localhost:8000/main for your urls in "main" app. If you want to do it without specifying main in the url in your browser, then change it to:
urlpatterns = [
path('', include('main.urls')),
path('admin/', admin.site.urls),
]

Import "blocktunes" could not be resolved Pylance report Missing Imports

urls.py
from django.contrib import admin
from django.urls import path, include
from blocktunes import views #error in blocktunes
urlpatterns = [
path('', include('blocktunes.urls')),
path('admin/', admin.site.urls),
path('', views.UserRegister_view)
]
Why is it showing missing imports?
settings.py
INSTALLED_APPS = [
'blocktunes.apps.blocktunesConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
PLEASE HELP.
Image link of structure of apps
[1]: https://i.stack.imgur.com/YhPEg.png
By adding the following command in .vscode of the folder, I was able to import blocktunes.
"python.analysis.extraPaths": ["./etherly"]

Importing Errors

I am getting errors in almost all imports please help.
i'm using django 2.2.5, python 3.7, but getting errors in unresolved import'django.contrib' ,unresolved import'django.urls',unresolved import'django.shortcuts' etc
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path("", include("hello.urls")),
path('admin/', admin.site.urls),
]
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello, Django!")
Message=No module named 'django'
File "C:\Users\Sharf\Desktop\python projects\p1\calc\urls.py", line 1,
in <module>
from django.urls import path
Can you post your settings.py file ? I think the problem comes from here ...
INSTALLED_APPS = [
'mainApp.apps.nameApp',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'channels'
]
ROOT_URLCONF = 'app.urls'

Adding new Django app - Getting 404 page not found

I have created a directory called vsdk which includes service_development (a voice application) and my newly created application called dashboard. Unfortunately I can’t seem to get the main page of dashboard to work. I get a 404 error when trying to access 127.0.0.1:8000/dashboard/, while doing everything similar to what I’ve done with service_development.
Would someone be able to help me?
Vsdk\settings.py
INSTALLED_APPS = [
'vsdk.service_development.apps.ServiceDevelopmentConfig',
'vsdk.dashboard.apps.DashboardConfig',
'storages',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Vsdk\dashboard\apps.py
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
class DashboardConfig(AppConfig):
name = 'vsdk.dashboard'
verbose_name = _("Dashboards")
Vsdk\urls.py
from django.conf.urls import url, include
from django.contrib import admin
from django.conf.urls.static import static
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.urls import include, path
admin.site.site_header = _("Petrichor Rain Service")
urlpatterns = [
url(r'^', admin.site.urls),
url(r'^vxml/', include('vsdk.service_development.urls')),
url(r'^vxml/', include('vsdk.dashboard.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Vsdk\dashboard\urls.py
from django.shortcuts import render
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]

Page not found (404) in Django view

I am trying to wire up a view based on the Django tutorial (1.8), and am for some reason not getting a basic url to work:
Page not found (404)
Settings
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'events',
)
In the main folder, I have these_events/these_events/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^/', include('events.urls')),
]
In the events app, I have these_events/events/urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r"^$", views.search_db, name='search-db')
]
these_events/events/views.py:
from django.shortcuts import render
from django.http import HttpResponse
def search_db(request):
return HttpResponse("hello, world")
This has me befuddled as I followed the example, and this is the way I remember using Django in the past.
In these_events/these_events/urls.py
try changing
url(r'^/', include('events.urls')),
to
url(r'', include('events.urls')),

Categories

Resources