Why cant python find my module?

2024/11/20 19:29:14

I'm getting this error every time I type python manage.py runserver in the root server of my Django app.

ImportError: No module named utils

I just added a new app to my project called 'utils' by running python manage.py startapp utils in the root directory of my project (/ecomstore/), and then moved it to the directory my book said to put it in.

Here's an overview of my project's directories, followed by my code:

ecomstore/

init.py

manage.py

settings.py

urls.py

views.py

wsgi.py

catalog.py/

init.py

admin.py

forms.py

models.py

tests.py

urls.py

views.py

static.py/

catalog.css

catalog.html

css.css

templates/

base.html

catalog/

catalog.html

index.html

tags/

utils/

init.py

models.py

tests.py

views.py

context_processors.py

The relevent code from my settings.py file is below:

INSTALLED_APPS = ('django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.sites','catalog','utils',# Uncomment the next line to enable the admin:'django.contrib.admin',# Uncomment the next line to enable admin documentation:# 'django.contrib.admindocs',
)

FWIW: I have also tried putting 'ecomstore.utils' under INSTALLED_APPS, and moving the utils directory to the root directory of my project. My book is called Beginning Django for Ecommerce and it's outdated. Thanks in advance for any help, I'm really stuck!

Answer
  • utils should be moved one level up, from "templates" to "ecomstore".
  • The init files should be named __init__.py, not init.py.
  • It is very unusual to have .py-endings for directories

I would strongly suggest to do teh django tutorial first if your book is outdated and after you succeed with this, try to adapt the book content to what you learned in the tutorial.

https://en.xdnf.cn/q/119799.html

Related Q&A

Seperating the numbers from strings to do the maths and return the string with the results [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 4…

Protect an API by using OAuth 2.0 with Azure Active Directory and API Management

I want to Protect amy API by using OAuth 2.0 with Azure Active Directory and API Management. I have added my API in API management and Im following this article https://learn.microsoft.com/en-in/azure…

How can filter by list in django

I am trying to filter a queryset by a list I am getting unicode data into format of 1,4,5,6 bycategory = request.GET.getlist(category) print type(category)data = Leads.objects.filter(item_required__id…

Python: get the return code of ant sub-process in windows

I use python to call ant, I want to get the return code of the ant for detect ant error.for example, in cmd.exe, C:\Documents and Settings\Administrator>ant sfsf Buildfile: build.xml does not exist!…

Skipp the error while scraping a list of urls form a csv

I managed to scrape a list of urls from a CSV file, but I got a problem, the scraping stops when it hits a broken link. Also it prints a lot of None lines, is it possible to get rid of them ? Would ap…

Getting the TypeError - int object is not callable [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

Reordering columns in CSV

Question has been posted before but the requirements were not properly conveyed. I have a csv file with more than 1000 columns:A B C D .... X Y Z 1 0 0.5 5 .... 1 7 6 2 0 0.6 4 …

Variable not defined in while loop in python?

I am trying to write a simple program in python to read command line arguments and print a final word based on the arguments. If there is any argument of the form "-f=" then the will go to t…

Hours and time converting to a certain format [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 3 years ago.Improve…

Python socket server: listening to multiple clients [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…