IMPORT PROBLEM

159 views
Skip to first unread message

Heman Okumbo

unread,
Sep 2, 2024, 1:50:38 AM9/2/24
to django...@googlegroups.com
My project url cannot import views from the app folder, what ks the problem?

Augusto Domingos

unread,
Sep 2, 2024, 2:45:04 AM9/2/24
to Django users

can you send some screenshots showings how you are importing the view?

Heman Okumbo

unread,
Sep 2, 2024, 3:44:46 AM9/2/24
to django...@googlegroups.com
Homeland is my project directory,there is another folder in the same directory with the same name,my apps directory is named land and its where i am trying to import views from.
I get the below traceback error when i try the import.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/64c28c86-41d4-4242-a8bf-05862a4b18fbn%40googlegroups.com.
Screenshot_20240902-103716.png
Screenshot_20240902-103659.png

Augusto Domingos

unread,
Sep 2, 2024, 5:11:17 AM9/2/24
to Django users

Good... it's just a path issue.

Instead of doing 'from . import views', try this: 'from {app_name} import views'.

In your case, you have an app named 'land', so it would look something like this:

'from land import views'.

You need to specify the app name because of the directory structure. When you use 'from . import', you're telling Django to import something from the current directory, which in your case is 'homeland'. However, 'homeland' typically doesn't contain an app directory.

And please make sure you actually created app with manage.py startapp {app_name} and included the app in your settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'land.apps.LandConfig' # your app
 
]

Heman Okumbo

unread,
Sep 2, 2024, 6:45:31 AM9/2/24
to django...@googlegroups.com

Thanks for the tip,what can be the problem if Django is not importing a function from the app directory ie from land import views,the function in views is pen, error traceback states there is no pen function in views.


Prashanth Patelc

unread,
Sep 2, 2024, 6:56:27 AM9/2/24
to django...@googlegroups.com


Use like this
path('pen/',views.land,name='pen'),


Talha Malik

unread,
Sep 2, 2024, 9:04:32 AM9/2/24
to django...@googlegroups.com

Is views.py in the same folder of urls.py or is views.py in the parent folder of urls folder?


Talha Malik

unread,
Sep 2, 2024, 9:04:37 AM9/2/24
to django...@googlegroups.com

Send the screenshot of folder structure, in which file you are importing and how you are importing?


--

Heman Okumbo

unread,
Sep 2, 2024, 10:14:42 AM9/2/24
to django...@googlegroups.com
Views.py is in the apps folder created by start app command on the terminal 

Olatide Joseph

unread,
Sep 3, 2024, 2:21:35 PM9/3/24
to django...@googlegroups.com

There's no file named views.py in that directory


Reply all
Reply to author
Forward
0 new messages