Reputation: 1454
This is my first time working with Django and while I'm finding the tutorial they provide to be very helpful, there is one major issue I'm having moving forward with my project.
The most confusing aspect of Django so far is the layout of files in a project. As of now, the layout of my project is as follows:
webapp/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
app/
__init__.py
models.py
tests.py
views.py
Bear with my naming here, I created a Django project "mysite" and an app "app". Here are the questions I find myself continually returning to:
I've noticed that in mysite/settings.py there is a section for apps, would I include the app I'm writing in this project in that section once I've finished it?
If I were to want to create a simple index.html page, where would a file like that go in this project organization?
I've read that static content like CSS or image files need to be contained within a simple "static" directory. Where would this go in this project organization? [ This would be for debugging purposes only, I've read this should never be done for production ]
My main goal right now is to just be able to view a simple html site before I begin delving into the models and views of the app I'm creating.
Upvotes: 1
Views: 485
Reputation: 616
If your app needs one or more setting variables, then yes, you would put those in mysite/settings.py
Create a new folder mysite/templates/
. This is where you want to put your template files. Organize your templates per app: mysite/templates/app/
would have the templates used by your app views. If you want to serve static templates such as a simple static index.html
, then just throw that file in mysite/templates/index.html
and then add the following to your urls.py
file (no need to create a view for the index):
(r'^$', 'django.views.generic.simple.direct_to_template', {'template': 'index.html'}),
Static content would end up in something like mysite/static
after you run the collectstatic
command. See managing static files. The collectstatic
command searches for static files in all locations specified in STATICFILES_DIRS
and deploys them into the folder specified in STATIC_ROOT
(mysite/static).
Upvotes: 1