So in my Django stucture (default setup), my folder structure goes like this:
/mysite
/mysite
__init.py
settings.py
urls.py
wsgi.py
/mymodel
...
/myapp
...
manage.py
So to access the settings file, wsgi.py is, by default, set to mysite/settings.py. However, Django gave the mysite name to 2 folders, one within the other. So it looks in the top level one, doesn't find it, and raises an error. I tried mysite/mysite/settings.py with the parent mysite's directory in the system path, but that gave the same error.
ImportError: Could not import settings 'mysite.mysite.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named mysite.mysite.settings
To get more info on this error, check How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi?
I'm just wondering why would Django make the default structure so difficult and if renaming stuff is the best way out? Seems it could be sloppy and an error-prone way of doing things. Not sure how many places I'd have to change the name if I did start renaming stuff. Seems dangerous.
By default, Django stores files locally, using the MEDIA_ROOT and MEDIA_URL settings. The examples below assume that you're using these defaults. However, Django provides ways to write custom file storage systems that allow you to completely customize where and how Django stores files.
Unfortunately, the Django development server doesn't serve media files by default. Fortunately, there's a very simple workaround: You can add the media root as a static path to the ROOT_URLCONF in your project-level URLs.
Django provides built-in library and methods that help to upload a file to the server. The forms. FileField() method is used to create a file input and submit the file to the server. While working with files, make sure the HTML form tag contains enctype="multipart/form-data" property.
The key point to understand is that the top-level mysite
is not a Python package (note that there's no __init__.py
). It's just a regular folder that's used for organizational purposes. (That's why mysite.mysite.settings
would never work, regardless of the PYTHONPATH
.)
All you need to do is make sure that the top-level mysite
directory is the only thing from this project on your PYTHONPATH
. Once you do that, everything should work the way you expect it to. (If you find the double-naming confusing, though, you certainly can, with some care, rename things.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With