Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django directory layout explanation

Tags:

django

So I have a django project I just created called 'coolprojectsite' the directory structure looks something as follows:

* media (dir)
* mytemplates (dir)
* * admin (dir)
* * coolprojects (dir)
* coolprojectsite (dir)
* * coolproject (dir)
* * * __init__.py
* * * admin.py
* * * models.py
* * * tests.py
* * * urls.py
* * * views.py
* * __init__.py
* * settings.py
* * urls.py

So I have a few questions.

1) Is coolprojectsite considered the 'project'

2) Is coolproject considered the 'application'

3) 'media' contains the css, javascript files etc. Is that the proper place for them? Its outside the project.

4) 'mytemplates' has specific files that contain django markup (e.g. {% %} ) and they are accessed because my urls.py points to them. Is it proper to have these files outside the project?

5) If I want to include some arbitrary javascript file (say jquery) do I just create a new entry in urls.py (if so, should it be the one in coolprojectsite, or coolproject) and then link to that url?

like image 575
Daniel Avatar asked Jun 25 '09 14:06

Daniel


People also ask

How do I organize my Django project?

The way I like to organize my Django Project is – Keeps all Django apps in apps folder, static files (scripts, js, CSS) in the static folder, HTML files in templates folder and images and media content in the media folder.

How does Django architecture work?

Every website has three main code sections: input logic, business logic, and user interface logic. The code has certain functions to perform, the input data is the dataset and how it is stored in the database. It is just a matter of delivering the input to the database in the desired format.

How do you describe a Django project?

Django is a high-level Python web framework that enables rapid development of secure and maintainable websites. Built by experienced developers, Django takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel.

What is a design pattern Django?

Unlike traditional Design Patterns, Django Design Patterns (DDP) are not strictly occurring patterns among the classes. DDPs are actually best practices followed by the Django developers. Before Diving into Pattens we need some basic knowledge about the various components of a Django Application.


1 Answers

  1. "Project" is not really a useful concept in Django. The Django tutorial mentions it, but the developers have frequently mentioned on mailing lists that they wish they hadn't introduced it. Basically, a project is just a container for your code - but in fact the code can live anywhere on the Pythonpath.

  2. Yes, and you can have multiple applications as long as they're all added to INSTALLED_APPS in settings.py.

  3. It doesn't matter where they live. You will need something to serve them - in development, it can be done with the built-in server, but in production you'll need to point Apache (or whatever) directly at the files.

  4. Doesn't matter. It's the views that load the templates, and again as long as TEMPLATE_DIRS is set properly in settings.py that's fine.

  5. No, absolutely not. As mentioned, static assets live in your media folder, and don't get served through Django.

like image 111
Daniel Roseman Avatar answered Sep 27 '22 23:09

Daniel Roseman