Django "apps" folder still relevant? - django

There was somewhere I read couple of years ago (Two scoops of Django 1.4?) suggested having an "apps" folder inside the Django project which hosts all the apps.
Repo folder
-- Project root folder
-- apps
-- app 1
-- app 2
-- settings etc
But just had a quick read of "Two scoops of Django 1.8" there is no mention of the "apps" folder in the preferred project structure.
Repo folder
-- Project root folder
-- app 1
-- app 2
-- settings etc
What have I missed? And why did they remove this folder?

I personally have gone back and forth on this one.
The new default layout of django is somewhat confusing - having two folders - one for the core software and one for your app.
The thing I have had issue with is by adding your app to the top level of the PYTHONPATH, another package installed from say someplace like PyPi will interfere with yours. For that reason alone I suggest 'namespacing' your apps inside the apps folder. I put 'namespacing' in quotes as by having something like 'myspecialproject' with 'myspecialproject.apps.payments' is a whole lot better than having 'payments' at the top level which will likely get clobbered by some other package.
So yes, I suggest an apps folder inside your project.

like #marcusshep said is just preference, anyway if you want to keep your apps inside this folder you can add this line after BASE_DIR var sys.path.insert(0, os.path.join(BASE_DIR, 'apps')). With this you don't have to use apps.app..., is like that folder doesn't exist

Related

How can I change the name(s) of folders in my Django project without destroying its ability to find its own parts?

I'm reading through Two Scoops of Django and the authors note that best practices involve having a config folder and an apps folder. I've been building a Django project for the last few months here & there and want to get in the habit of complying with these practices, but when I change the name of my <project_name> folder (with the wsgi, settings, etc.), Django can't seem to find the contents of the folder anymore.
How do I change this folder name and put the project apps into an app folder without breaking the connections they have?
Restoring connection can be a painful process and even if you restore the connections, there is no guarantee it will always work (eg, some 3rd party app may fail because of dependency issues which you forgot to change).
I do like to separate my created apps and project folder to be visibly different too. For this, I create parent folder which would be my entire django installation and then inside the created folder I create the project while telling that this is the directory I'd like to use. Lets say I want to create blog project:
$ mkdir blog
$ cd blog
$ django-admin startproject blog_project .
This will give you a blog folder and inside it you will get blog_project folder and beloved manage.py.

django directory structure the "django way"? (/root/project/app or /root/project & root/app)?

I have a pretty simple question here:
I'm starting out with Django but i'm needing to know which one of the following is more proper (the django way):
Having the app under the django_project like this: /root/project/app
Or Having the Django_project and the django_app under the same /root/ directory in parallel?
There are several thoughts of how to do this best, and only you and your team can find out what works best for you. The Django tutorial recommends keeping apps in parallel to the configuration directory. My team has settled on a few things over time:
From the project root:
.gitignore
manage.py
README.md
+---config
+---urls.py
+---wsgi.py
+---settings.py
+---requirements
+---templates
+---static
+---app1
+---models.py, etc
+---app2
Some prefer another directory layer above the project level, but that has felt like overkill to our projects. We have settled as a team on naming each project's configuration subdirectory config, rather than the project name repeated. This is just personal preference, but has worked for us. Good luck!

Installing Pinax, where is my deployment folder?

I'm trying to set up Pinax and I'm new to everything involved (Django, Pinax, webservers, etc). I'm following http://pinax.readthedocs.org/en/latest/gettingstarted.html
When I generate a project using:
(mysite-env)$ pinax-admin setup_project -b basic mysite
The directory structure I get is:
apps __init__.py manage.py settings.pyc urls.py
dev.db __init__.pyc requirements static urls.pyc
fixtures locale settings.py templates wsgi.py
Which as far as I can tell is missing the deployment folder (when you compare to the directory structure shown here : http://pinax.readthedocs.org/en/latest/starterprojects.html). It doesn't seem to be effecting anything yet, but it makes me nervous. What is going on and is the fact I'm missing the deployment folder going to cause problems in the future?
I'm running Ubuntu and using python 2.7. I had the same behaviour with Windows 7, python 2.6
Thanks!
The new Django versions have made the old pinax pretty much useless. Now Django supports project templates and Pinax is separated into several smaller projects regarding starter projects (such as pinax-project-account) and apps (such as django-user-account).
The current way to use pinax is to choose a starter project, and then running something like:
$ django-admin.py startproject --template=https://github.com/pinax/pinax-project-account/zipball/master <project_name>
and then install requirements:
$ pip install -r requirements.txt
This will create a new Django project using the starter-project as a template, which already includes a few apps (like django-user-account) and templates (with bootstrap!). The project is ready to run, and already includes a bunch of functionality (like user registration, login and management).
Also, Django has changed the project directory structure a bit, so now it doesn't really look like that anymore.

Separate Git repository for multiple Django sites

I am using Django as development framework for my current Project (say Project A).
I want to create a new application (say Project B) that has different views as Project A. But this new Project B is going to use most of the existing backend modules and models from current Project A.
Such that my Current Project (Project A) is hosted on URL http://www.site-one.com and and New Project B will be hosted on http://www.site-two.com. With respect to this, I have one doubt and a question that I want to ask:
Doubt: Is my choice of using "Django sites framework" for this is correct?
Question: Is there any way to keep two Django sites (A and B) in different Git Repo and still access the models and other modules from Current Site A?
I would suggest for shared functionality create separate django apps with a structure resembling something like the following. (I'm assuming you've got your projects in virtualenvs)
appname/
__init__.py
models.py
views.py
templates/
base.html
Store this app in a git repository of it's own.
then inside the requirements.txt for each of your projects this functionality is needed in add a line like the following, assuming you're using bitbucket:
-e git+https://yourusername#bitbucket.org/appname/appname.git#egg=appname
install
pip install -r requirements.txt
then in your settings.py add myappname to your INSTALLED_APPLICATIONS

Appropriate placement for my testcases belonging to a non-app in Django

I have built my website in Django. And like any other django project I have got apps inside the project root directory and some special folders like(extensions a.k.a custom django command extensions). With an app, we dont have any problem with having testcases. "tests.py" inside the app directory will be the solution. But for a special folder(which is not an app or which doesn't have a models.py) where do I place the testcases. I tried placing the tests.py inside the extensions directory and it said the directory is not a model and unable to run the tests. HOw do I solve this? How can I have a proper placement of testcases related to non-apps?
I think it will work to put them in a tests/ directory at the project level.
If, for some reason, it doesn't then try creating an empty models.py in your extensions directory.