Amirali
Amirali

Reputation: 1

importError:cannot import name 'home_page' from 'shop.views'

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),
]

Upvotes: 0

Views: 407

Answers (3)

BiswajitPaloi
BiswajitPaloi

Reputation: 641

** 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}....

Upvotes: 0

Paullaster Okoth
Paullaster Okoth

Reputation: 87

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),

Upvotes: 0

Dimitar
Dimitar

Reputation: 520

You should add your app_label to the import as well. from {app_name}.views import home_page

Upvotes: 1

Related Questions