Issue
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path("", views.home),
path("predict/", views.predict),
path("predict/result", views.result)
the traceback is
File "C:\Users\user\PycharmProjects\Diabetes Prediction\Diabetes_Prediction\Diabetes_Prediction\urls.py", line 19, in <module>
from . import views
ImportError: attempted relative import with no known parent package
Solution
You are mixing up your project level urls.py with your app urls.py. Your project urls.py is found in the directory containing your settings.py. It should look like this:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myapp.urls')),
]
Your app urls.py should be created in your app directory i.e. where you have your views and models. Create a file named urls.py in that directory. It should look like this:
from django.urls import path
from . import views
app_name = 'myapp'
urlpatterns = [
path(" ", views.home),
path("predict/", views.predict),
path("predict/result", views.result)
OP did not write app name in settings.py. Include your app name in settings.py as shown below:
INSTALLED_APPS = [
# Default apps
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# My apps
'myapp',
]
Please read as you seem to be mixing up a lot of things. Also read the docs I included A typical Django project is made up of one or more apps. You create your project using the command django-admin startproject your_project_name .
and you create your app using the following command python manage.py startapp your_app_name
. Please make sure you're not mixing up both. Also make sure you included your appname in INSTALLED_APPS
list in your settings.py
See docs for more.
Answered By - journpy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.