I use WebFaction for hosting.
On their website I created a Django project.
It gave me this directory setup:
/home/account_username/webapps/app_name/myproject/myproject/
Why "myproject" is used twice here?
I do not understand what each directory should be used for.
I do not understand which files should be in each directory.
Here is what's inside each directory:
app_name
apache2
bin
myproject
manage.py
myproject
init.py
init.pyc
settings.py
settings.pyc
tests.py
urls.py
urls.pyc
views.py
views.pyc
wsgi.py
What is the first "myproject" directory supposed to be used for?
What do most people name this directory?
What is the second "myproject" directory supposed to be used for?
What do most people name this directory?
WebFaction is using Django 1.4 and default project layout is been changed. See the Django 1.4 release notes for more details. You will get all answers.
Related
Assume you have a directory where you keep all your Django projects:
$HOME/Programming/Django_Projects
If you in this directory call
django-admin startproject blog
you'll end up with the following director tree:
$HOME/Programming/Django_Projects/blog
$HOME/Programming/Django_Projects/blog/blog
What's the first blog and whats blog/blog?
When you use the command:
django-admin startproject blog
The first blog is just a website folder or simply a container for your project. The blog subfolder is the actual project folder which contains the following:
$HOME/Programming/Django_Projects/blog/blog/
__init__.py
settings.py
urls.py
wsgi.py
Bottom line is, the first blog is simply a container of your django project/files. You can always change its filename and it won't affect anything Django-related.
Also, what you can do is make use of:
django-admin startproject blog .
Notice the . after the name of your project, this will allow you to create a project directly in the current directory without having blog/blog
So, if you do:
$HOME/Programming/Django_Projects> mkdir first_django_project
$HOME/Programming/Django_Projects> cd first_django_project
$HOME/Programming/Django_Projects> django-admin startproject blog .
What you'll get is this project tree:
$HOME/Programming/Django_Projects/first_django_project/
blog/
__init__.py
settings.py
urls.py
wsgi.py
manage.py
Therefore no duplicate/confusing names.
In pycharm under external libraries I'm not able to see all files (e.g all templates are missing).
The external librarys are coming from a remote server (docker).
On the server itself, I'm able to see every file.
Pycharm
Docker container
root#fcb645e62162:/usr/local/lib/python3.5/site-packages# ls django/contrib/admin
__init__.py actions.py checks.py exceptions.py forms.py locale models.py sites.py templates tests.py views
__pycache__ apps.py decorators.py filters.py helpers.py migrations options.py static templatetags utils.py widgets.py
This should work in the latest PyCharm build, but maybe there's something
special in your case that breaks it.
Try update version.
or go to Settings | Project Structure and add the folder with
your Django installation as a content root to your project.
Im trying to deploy my django proyect under a webfaction server. I have an app named "home".
FACT A) If i move my "home" folder to the same directory of manage.py and i set my setting.py like this, the app works fine.
INSTALLED_APPS = (
'home'
)
FACT B) If i move my "home" folder to the apps directory, and set my settings.py like this, i recive an error "No module named myproject.apps.home"
INSTALLED_APPS = (
'myroject.apps.home'
)
The thing is i want to set my "home" app under the apps folder. Where could be the problem? i've been trying to configurate httpd.conf in apache but i didn't succeed.
This is my folder tree:
myproject_name
-apache2
-bin
-lib
--myproject
-manage.py
--myproject
-wsgi.py
-urls.py
-__init__.py
-settings.py
-apps
Django version: 1.4.2
python version: 2.7
mod_wsgi version: 3.4
Thanks for your time
The home and apps folders must have __init__.py file to be considerd as a package. Make sure you have it there.
I'm trying out Django for the first time, and I'm trying to follow the tutorial provided by the django team.
After I've created a new project I get the following folder/file structure, just as the tutorial says I should:
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
When I create an app I run:
python manage.py startapp polls
...which creates the app 'polls' in the same folder as the manage.py file - which gives me:
mysite/
manage.py
polls/
__init__.py
admin.py
models.py
tests.py
views.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
This means the app I created gets created outside my project folder, which, of course, should not be the case. I have tried to move manage.py inside the project folder. But when I do that and run:
python manage.py syncdb
...I get the following error:
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'testproject.settings' (Is it on sys.path?): No module named testproject.settings
I guess I could move the app manually to the project folder, but this is something I shouldn't have to do.
So, either something is wrong in the tutorial (which I have very hard to believe), or I'm missing something out here (more likely).
Thanks in advance.
This is the new proper layout. "mysite/mysite" is an app, and "mysite/polls" is an app. The "mysite" parent folder is your project folder.
#holyredbeard that is the correct layout are you reading the older documentation?
Useful reading: http://www.tdd-django-tutorial.com/blog/articles/2012/tutorials-updated-django-14-and-its-weird-new-fold/
Don't move the manage.py it should sit outside the apps and the project folder.
since 1.4 common layout example...
project_root/
project_name/
media/
static/
static_root/ (in production)
templates/some_app/foo.html (overriding some_app at project level)
/admin/some_app/some_model/change_list.html
(overriding admin changelist for some_app.models.some_model)
settings.py
settings_deployment.py
urls.py
some_app/
templates/some_app/foo.html
urls.py
views.py
models.py
manage.py
This is the official layout since version 1.4.
The rationale behind is explained well in the release notes:
https://docs.djangoproject.com/en/dev/releases/1.4/#updated-default-project-layout-and-manage-py
Do not move manage.py. In general you can expect that Django's own scripts always do the right thing, you never need to move any files just to get it working.
My django project in eclipse has this project structure:
main-project-folder/
src/
main-app/
app1/
app2/
settings.py
manage.py
urls.py
__init__.py
media/
templates/
Can i deploy the project with this structure? In other words, is right way to put src and other folders (media, tempaltes, etc.) in the root folder of my server (where my domain is linked)?
Like:
my-server-folder/
src/
media/
...
I imagine that in my-server-folder i should put the entry point of project, but in my project i haven't an entry point in main-project-folder, or does django automatically redirect to an entry point of src/main-app folder (i think that it doesn't because i don't find any options that say to django to do it)?
Sure. That's a fine directory structure.
Keep in mind your web server isn't going to know what to do with the Django project unless you tell it. If your web server is Apache (which it probably is if you don't know) look here for instructions to set it up to run the Django app:
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/
And here for WSGI:
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
Django apps aren't like PHP where you just upload them to the web server and they work.