Issue
So in my urls.py folder, I have the following code:
from django.urls import path
from view import views
#URLConf
urlpatterns = [
path('hello/', views.say_hello)
]
The error I get when I am trying to python manage.py runserver is
File "/Users/swathikumar/Desktop/storefront/playground/urls.py", line 3, in from view import views ModuleNotFoundError: No module named 'view'
View is a folder I created which has both init.py file and views.py file which has the following code:
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
# request -> response
# request handler
# action
def say_hello(request):
return HttpResponse('Hello World.')
I do not know how to solve this error of resolving the import of views into urls.py. All these files are in a playground app folder.
I was expecting my serevr to give me Hello World upon entering the http request.
Solution
You need to import the views from the current folder so you can access the current folder with dot(.) For example:
from . import models
from . import views
You can try this code
from django.urls import path
from . import views
#URLConf
urlpatterns = [
path('hello/', views.say_hello)
]
Answered By - Aditya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.