Reputation: 170
I have just started a Django project and spun up a web server. I have made minimal changes which I will post below. When I start my server, I am given a url which I click on to navigate to my web app. I see the following error
I am running python manage.py runserver
to run my server
Following are the only changes I have made to the files:
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pages.apps.PagesConfig',
]
urls.py
from django.urls import path
from .views import HomePageView
urlpatterns = [
path('', HomePageView, name='home'),
]
urls.py in the project folder
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('pages.urls'))
]
views.py
from http.client import HTTPResponse
from django.http import HttpResponse
def HomePageView(request):
return HTTPResponse("Hello Django")
Upvotes: 0
Views: 246
Reputation: 195
You have the wrong import, this is how it should be written to avoid the error,
from django.http import HttpResponse
def HomePageView(request):
return HttpResponse("Hello Django")
Notice I removed your first import line and changed the return statement.
Upvotes: 1