Deploying django: "no module named.." - django

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.

Related

pycharm django debug configrations doesn't recognize apps folder

All my apps are in apps folder
I also added sys.path.insert(0, os.path.join(BASE_DIR, "apps"))
in settings.py
my project structure as below:
But when I simply create and run a default Django Server in Pycharm (2019.1)
It returned an error
... 'apps' is not a package
My project runs perfectly in pipenv shell; python manage.py runserver
Can anyone help me, please?
I figure out it's due to the Content Root setting
My Git root is dwhnt but my Django root is dwhnt/proj
After deleting the old Content Root and set it with as below it works

location of settings.py for django project hosted in Google App Engine

I've problems running the simplest django project within GAE.
After running django-admin startproject myproj (Using django 1.4 from Google SDK), the folder hierarchy look as:
+ myproj (root folder of project)
- manage.py
+ myproj (a sub folder for the project files)
- __init__.py
- settings.py
- urls.py
- wsgi.py
I then add the usual app.yaml to the root folder - that is to the same folder where manage.py is.
application: u-pavarotti
version: 1
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: django
version: "1.4"
builtins:
- django_wsgi: on
syncdb, dbshell, shell ... works great. Even manage.py runserver works file. However, trying to run dev_appserver fails. The exception I get is:
ImportError: Could not import settings 'settings'.
Well, taking a look at google/appengine/ext/django/main (which django_wsgi is basically setting a URL handler for .* to the google.appengine.ext.django.main.app) is appears that it expect to find settings in the python path. But without doing anything, the module to import is myproj.settings (as myproj isn't in the path).
Now, adding .../myproj/myproj (the lower folder) to the PYTHONPATH solve everything on my dev machine, but as I have no control on the search path on the GAE deployment - this solution won't work.
I can move all files, or just settings.py up to the upper myproj, or move app.yaml down (kinda same thing), but it requires various changes form the default genereated settings.py - and I don't this is the way to go. Alternatively, I can write my own handler, which will instantiate django.core.handlers.wsge.WSGIHandler (old tutorials used to do that) - again, seems against the intention of at least the creators of the 'builtin' attribute of app.yaml.
I wonder how everyone else is solving this issue, and what is the right thing to do.
You can declare the environment variable DJANGO_SETTINGS_MODULE in your app.yaml:
env_variables:
DJANGO_SETTINGS_MODULE: 'myproj.settings'

Django can't load app

I'm using django 1.4, after i created the project using django-admin, I create an app, add it to settings.py in INSTALLED_APPS but then when I do manage.py runserver I get Error: no module named myapp
Does anyone know why?
Make sure you have two things:
correct path. You should be able to do ./manage.py shell and then import 'myapp' if not try 'myproject.myapp'
models.py in your app folder and __init__.py

Deploy Django project: folder/project structure

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.

How do I include a Django app in my PYTHONPATH?

I want to be able to import things from applications in my project without referring to my project name.
My folder structure is like so; I have a project called djangoproject1, and inside I have a folder called apps, and then I have my individual apps in that folder.
djangoproject1, apps, and all my applications have an empty "__init__.py" file in them.
In my settings.py file I have the following code:
import os
import sys
PROJECT_ROOT = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(PROJECT_ROOT, "apps"))
I've tried adding my apps to INSTALLED_APPS several ways:
'djangoproject1.apps.app1',
'djangoproject1.apps.app2',
or
'apps.app1',
'apps.app2',
or
'app1',
'app2',
but nothing works. Whenever I try to do:
from app1 import *
I got an unresolved import error. I'm using the latest versions of eclipse and django
Ok, so I got it to work by adding the apps folder to the PYTHONPATH through eclipse under Project Properties. Is this eclipse only though? I'm not sure how this will work when I try and deploy the site. What do you guys think?
The statement sys.path.insert(0, os.path.join(PROJECT_ROOT, "apps")) looks OK to me. Following this you only need to add app1 to INSTALLED_APPS and everything should work. But apparently they are not working.
Try the following: 1. Print your sys.path and verify that your project's app directory is in the list. 2. Double check that your have an __init__.py inside your apps folder.
Update
OK. Now can you fire up Django shell and try importing again? If it fails, please post the stack trace here.
You must include apps directory to PYTHONPATH. Be sure that in apps directory don't have __init__.py, because it become a package instead of "simple directory". Than, include in settings.py
app1, app2, app3
Use
from app1 import *