How set setting environment with DJANGO_SETTINGS_MODULE - python

I am new in Python \ Django and I have some question about settings environment. I use git for edit my project and on server I have production project. But when I edit project on local machine I have my own settings(DATABASE) so if I pull edited project on server I need to change my settings, so I want to set DJANGO_SETTINGS_MODULE, but I don't know what path I must set and where I must allocate my default setting.
This is my hierarchy:
wow
├── core
│   ├── admin.py
│   ├── api_views.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── __init__.py
│   │   └── __pycache__
│   ├── models.py
│   ├── __pycache__
│   │   ├── admin.cpython-35.pyc
│   │   ├── api_views.cpython-35.pyc
│   │   ├── __init__.cpython-35.pyc
│   │   ├── models.cpython-35.pyc
│   │   ├── sitemap.cpython-35.pyc
│   │   ├── urls.cpython-35.pyc
│   │   └── views.cpython-35.pyc
│   ├── sitemap.py
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── manage.py
├── media
│   └── core
│   ├── iUcZCekdW68_FrqsEHv.jpg
│   ├── iUcZCekdW68.jpg
│   ├── qWI5I5NuIeg.jpg
│   ├── server1.png
│   └── server2.png
├── not_found
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   ├── __init__.py
│   │   └── __pycache__
│   ├── models.py
│   ├── __pycache__
│   │   ├── admin.cpython-35.pyc
│   │   ├── __init__.cpython-35.pyc
│   │   ├── models.cpython-35.pyc
│   │   ├── urls.cpython-35.pyc
│   │   └── views.cpython-35.pyc
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── requirements.txt
├── settings.py
├── static
│   ├── admin
│   │   ├── css
│   │   ├── fonts
│   │   ├── img
│   │   └── js
│   └── core
│   ├── css
│   ├── img
│   └── js
├── staticfiles
│   ├── admin
│   │   ├── css
│   │   ├── fonts
│   │   ├── img
│   │   └── js
│   └── core
│   ├── css
│   ├── img
│   └── js
├── templates
│   ├── 404.html
│   ├── admin
│   │   ├── base.html
│   │   ├── base_site.html
│   │   └── index.html
│   ├── character.html
│   ├── characters.html
│   ├── checkout.html
│   ├── index.html
│   └── server.html
├── url.xml
└── wow
├── gunicorn.conf.py
├── __init__.py
├── __pycache__
│   ├── __init__.cpython-35.pyc
│   ├── settings.cpython-35.pyc
│   ├── urls.cpython-35.pyc
│   └── wsgi.cpython-35.pyc
├── settings.py
├── urls.py
├── views.py
└── wsgi.py
What i must do, end where i must write os.environ["DJANGO_SETTINGS_MODULE"] = wow.settings, or something like this?

Related

ckeditor does not shown when served from local

flask-ckeditor module work from cdn but when I served from local it does not shown, and my ckeditor is a custom build.
├── app.py
├── static
│   ├── ckedit
│   │   ├── build
│   │   │   ├── ckeditor.js
│   │   │   ├── ckeditor.js.map
│   │   │   └── translations
│   │   ├── ckeditor5-32.0.0-ia4y775k4cd6.zip
│   │   ├── LICENSE.md
│   │   ├── package.json
│   │   ├── README.md
│   │   ├── sample
│   │   │   ├── index.html
│   │   │   └── styles.css
│   │   ├── src
│   │   │   └── ckeditor.js
│   │   └── webpack.config.js
│   └── css
│   └── style.css
├── templates
│   └── index.html
└── venv
├── bin
├── lib
└── pyvenv.cfg
flask 2.0.3
flask-CKEditor 0.4.6
* by the way samples are working fine but because of uploader I don't wanna use ckeditor without module

Gunicorn giving me Module Not Found Error

I'm attempting to build a Django blog.
I have a couple of apps in there, but for some reason Gunicorn is giving me trouble with the error - ModuleNotFoundError: No module named 'blog.wsgi'
├── Procfile
├── blog
│   ├── blog
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-36.pyc
│   │   │   ├── settings.cpython-36.pyc
│   │   │   ├── urls.cpython-36.pyc
│   │   │   └── wsgi.cpython-36.pyc
│   │   ├── settings.py
│   │   ├── urls.py
│   │   └── wsgi.py
│   ├── db.sqlite3
│   ├── manage.py
│   ├── media
│   │   ├── 1820-3-large.jpg
│   │   ├── 1820-3-large_XGHcfcZ.jpg
│   │   ├── 1820-3-large_ZTmLkYt.jpg
│   │   ├── 1820-3-large_dPbPsPW.jpg
│   │   └── paul-morris-144777.jpg
│   ├── posts
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-36.pyc
│   │   │   ├── admin.cpython-36.pyc
│   │   │   ├── models.cpython-36.pyc
│   │   │   └── views.cpython-36.pyc
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── migrations
│   │   │   ├── 0001_initial.py
│   │   │   ├── 0002_auto_20171217_0000.py
│   │   │   ├── __init__.py
│   │   │   └── __pycache__
│   │   │   ├── 0001_initial.cpython-36.pyc
│   │   │   ├── 0002_auto_20171217_0000.cpython-36.pyc
│   │   │   └── __init__.cpython-36.pyc
│   │   ├── models.py
│   │   ├── static
│   │   │   └── posts
│   │   │   ├── css
│   │   │   ├── img
│   │   │   │   └── home.jpg
│   │   │   └── js
│   │   ├── templates
│   │   │   └── posts
│   │   │   ├── home.html
│   │   │   └── post_details.html
│   │   ├── tests.py
│   │   └── views.py
│   └── sitepages
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   ├── admin.cpython-36.pyc
│   │   ├── models.cpython-36.pyc
│   │   └── views.cpython-36.pyc
│   ├── admin.py
│   ├── apps.py
│   ├── migrations
│   │   ├── __init__.py
│   │   └── __pycache__
│   │   └── __init__.cpython-36.pyc
│   ├── models.py
│   ├── static
│   │   └── sitepages
│   │   ├── css
│   │   │   └── about.css
│   │   ├── img
│   │   └── js
│   ├── templates
│   │   └── sitepages
│   │   └── about.html
│   ├── tests.py
│   └── views.py
├── requirements.txt
└── venv
`
This is the bulk of my file tree as I see it. I don't see any issues, but I'm definitely overlooking something. Let me know if you'd like to see any other pieces of code.
My Procfile says -
web: gunicorn blog.wsgi --log-file -
This is my wsgi.py file -
This is wsgi.py -
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blog.settings")
application = get_wsgi_application()

Django ModuleNotFound For scripts

This has been driving me up the wall. I have a Django project with the following tree structure, and am trying to run python helper_scripts/load_professors_into_db.py from the root directory
load_professors_into_db.py has the following code:
## TODO: FIX THIS DAMN IMPORT PATH. THE SCRIPT DOESNT RUN CAUSE OF IT
from ocubulum_dashboard.models import Researcher
import pandas as pd
df = pd.read_csv("helper_scripts/soc_myaces_list.csv")
df = df.dropna()
df = df[~pd.isnull(df["scopus_id"])]
df = df[df["scopus_id"] != 'None']
However, it keeps trying ModuleNotFound errors. I've tried adding __init__.py files everywhere, but that doesn't work either.
Traceback (most recent call last):
File "helper_scripts/load_professors_into_db.py", line 10, in <module>
from ocubulum_dashboard.models import Researcher
ModuleNotFoundError: No module named 'ocubulum_dashboard'
The problem doesn't only occur for this. For other scripts that I want to run such as scopus_scraper.py, I face this ridiculous import issue as well.
Traceback (most recent call last):
File "data_collectors/scopus/scopus_scraper.py", line 1, in <module>
from ocubulum_dashboard.models import Researcher
ModuleNotFoundError: No module named 'ocubulum_dashboard'
Can someone point me as to how to solve this problem? I'm on python 3.6.
Entire Folder Structure:
├── data_aggregators
│   ├── myaces_aggregator.py
│   └── scopus_aggregator.py
├── data_collectors
│   ├── execute_all.py
│   ├── __init__.py
│   ├── journals
│   │   ├── __init__.py
│   │   ├── journal_scraper.py
│   │   ├── master.py
│   │   ├── __pycache__
│   │   │   └── __init__.cpython-36.pyc
│   │   └── test.json
│   ├── nus_myaces
│   │   ├── __init__.py
│   │   ├── master.py
│   │   └── __pycache__
│   │   └── __init__.cpython-36.pyc
│   ├── __pycache__
│   │   └── __init__.cpython-36.pyc
│   └── scopus
│   ├── __init__.py
│   ├── master.py
│   ├── __pycache__
│   │   └── __init__.cpython-36.pyc
│   ├── scopus_scraper.py
│   └── scopus_wrapper
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   └── scopus_wrapper.cpython-36.pyc
│   └── scopus_wrapper.py
├── environment.yml
├── helper_scripts
│   ├── __init__.py
│   ├── load_professors_into_db.py
│   ├── __pycache__
│   │   └── __init__.cpython-36.pyc
│   └── soc_myaces_list.csv
├── __init__.py
├── manage.py
├── ocubulum
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   ├── settings.cpython-36.pyc
│   │   ├── settings_development.cpython-36.pyc
│   │   ├── urls.cpython-36.pyc
│   │   ├── views.cpython-36.pyc
│   │   └── wsgi.cpython-36.pyc
│   ├── settings_development.py
│   ├── settings.py
│   ├── static
│   ├── urls.py
│   ├── views.py
│   └── wsgi.py
├── ocubulum_dashboard
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── __init__.py
│   │   └── __pycache__
│   │   ├── 0001_initial.cpython-36.pyc
│   │   └── __init__.cpython-36.pyc
│   ├── models.py
│   ├── __pycache__
│   │   ├── admin.cpython-36.pyc
│   │   ├── apps.cpython-36.pyc
│   │   ├── __init__.cpython-36.pyc
│   │   ├── models.cpython-36.pyc
│   │   ├── tests.cpython-36.pyc
│   │   └── views.cpython-36.pyc
│   ├── static
│   │   ├── css
│   │   │   ├── custom.css
│   │   │   └── side-menu.css
│   │   ├── img
│   │   │   └── logo.png
│   │   └── js
│   │   └── ui.js
│   ├── templates
│   │   └── ocubulum
│   │   ├── dashboard.html
│   │   └── layout.html
│   ├── tests.py
│   └── views.py
├── Procfile
├── __pycache__
│   └── __init__.cpython-36.pyc
├── README.md
├── requirements.txt
└── runtime.txt
Try from ..ocubulum_dashboard.models import Researcher.
Or add the folder containing ocubulum_dashboard to your PYTHONPATH.

Getting the python path set up properly scrapy/django

I have a scrapy project that I put it inside a Django project root folder.
And I have these lines added to the setting :
import sys
import os
sys.path.append('/home/user/Django-projects/first_project')
os.environ['DJANGO_SETTINGS_MODULE'] = 'first_project.settings'
Now when I try to import a model in items.py :
from blog.models import Annonce
I get this message :
ImportError: No module named blog.models
Django project directory:
.
├── assets
│   ├── logo.jpg
│   └── screen.png
├── blog
│   ├── admin.py
│   ├── admin.pyc
│   ├── forms.py
│   ├── forms.pyc
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── models.py
│   ├── models.pyc
│   ├── tests.py
│   ├── urls.py
│   ├── urls.pyc
│   ├── views.py
│   └── views.pyc
├── database.sql
├── first_project
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── manage.py
├── scrapy project
│   ├── marocannonces
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── items.py
│   │   ├── items.pyc
│   │   ├── middlewares.py
│   │   ├── middlewares.pyc
│   │   ├── pipelines.py
│   │   ├── pipelines.pyc
│   │   ├── settings.py
│   │   ├── settings.pyc
│   │   └── spiders
│   │      └── some spiders here...
│   ├── scrapy.cfg
└── templates
└── blog
├── contact.html
├── home.html
└── read.html
How can I fix this please ?

Serving django app with apache2+mod_wsgi

I have configured a linode server with apache2 and mod_wsgi..
the server is running
wsgi is running
postgre is running and syncdb was successful
what I am having trouble finishing is actually serving the app..
my file structure:
.
├── logfile
└── srv
├── logfile
└── www
└── quickerhub.com
├── admin
│   ├── css
│   │   ├── base.css
│   │   ├── changelists.css
│   │   ├── dashboard.css
│   │   ├── forms.css
│   │   ├── ie.css
│   │   ├── login.css
│   │   ├── rtl.css
│   │   └── widgets.css
│   ├── img
│   │   ├── changelist-bg.gif
│   │   ├── changelist-bg_rtl.gif
│   │   ├── chooser-bg.gif
│   │   ├── chooser_stacked-bg.gif
│   │   ├── default-bg.gif
│   │   ├── default-bg-reverse.gif
│   │   ├── deleted-overlay.gif
│   │   ├── gis
│   │   │   ├── move_vertex_off.png
│   │   │   └── move_vertex_on.png
│   │   ├── icon_addlink.gif
│   │   ├── icon_alert.gif
│   │   ├── icon_calendar.gif
│   │   ├── icon_changelink.gif
│   │   ├── icon_clock.gif
│   │   ├── icon_deletelink.gif
│   │   ├── icon_error.gif
│   │   ├── icon-no.gif
│   │   ├── icon_searchbox.png
│   │   ├── icon_success.gif
│   │   ├── icon-unknown.gif
│   │   ├── icon-yes.gif
│   │   ├── inline-delete-8bit.png
│   │   ├── inline-delete.png
│   │   ├── inline-restore-8bit.png
│   │   ├── inline-restore.png
│   │   ├── inline-splitter-bg.gif
│   │   ├── nav-bg.gif
│   │   ├── nav-bg-grabber.gif
│   │   ├── nav-bg-reverse.gif
│   │   ├── nav-bg-selected.gif
│   │   ├── selector-icons.gif
│   │   ├── selector-search.gif
│   │   ├── sorting-icons.gif
│   │   ├── tool-left.gif
│   │   ├── tool-left_over.gif
│   │   ├── tool-right.gif
│   │   ├── tool-right_over.gif
│   │   ├── tooltag-add.gif
│   │   ├── tooltag-add_over.gif
│   │   ├── tooltag-arrowright.gif
│   │   └── tooltag-arrowright_over.gif
│   └── js
│   ├── actions.js
│   ├── actions.min.js
│   ├── admin
│   │   ├── DateTimeShortcuts.js
│   │   ├── ordering.js
│   │   └── RelatedObjectLookups.js
│   ├── calendar.js
│   ├── collapse.js
│   ├── collapse.min.js
│   ├── core.js
│   ├── getElementsBySelector.js
│   ├── inlines.js
│   ├── inlines.min.js
│   ├── jquery.init.js
│   ├── jquery.js
│   ├── jquery.min.js
│   ├── LICENSE-JQUERY.txt
│   ├── prepopulate.js
│   ├── prepopulate.min.js
│   ├── SelectBox.js
│   ├── SelectFilter2.js
│   ├── timeparse.js
│   └── urlify.js
├── interest
│   ├── django.wsgi
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   └── wsgi.py
├── js
│   └── jquery-1.10.1.min.js
├── logfile
├── manage.py
├── README
├── reoccurring
│   ├── admin.py
│   ├── forms.py
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── models.py
│   ├── models.pyc
│   ├── usagelib.py
│   └── views.py
├── schedule
│   ├── admin.py
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── models.py
│   ├── models.pyc
│   ├── tests.py
│   ├── usagelib.py
│   └── views.py
├── src
│   ├── facebooksdk
│   │   ├── examples
│   │   │   ├── appengine
│   │   │   │   ├── app.yaml
│   │   │   │   ├── example.html
│   │   │   │   └── example.py
│   │   │   ├── newsfeed
│   │   │   │   ├── app.yaml
│   │   │   │   ├── facebookclient.py
│   │   │   │   ├── static
│   │   │   │   │   ├── base.css
│   │   │   │   │   ├── favicon.ico
│   │   │   │   │   └── robots.txt
│   │   │   │   └── templates
│   │   │   │   ├── base.html
│   │   │   │   ├── home.html
│   │   │   │   └── index.html
│   │   │   ├── oauth
│   │   │   │   ├── app.yaml
│   │   │   │   ├── facebookoauth.py
│   │   │   │   └── oauth.html
│   │   │   └── tornado
│   │   │   ├── example.html
│   │   │   ├── example.py
│   │   │   └── schema.sql
│   │   ├── facebook.py
│   │   ├── facebook_sdk.egg-info
│   │   │   ├── dependency_links.txt
│   │   │   ├── PKG-INFO
│   │   │   ├── SOURCES.txt
│   │   │   └── top_level.txt
│   │   ├── MANIFEST.in
│   │   ├── README.rst
│   │   └── setup.py
│   └── pip-delete-this-directory.txt
├── static
│   └── js
│   └── jquery-1.10.1.min.js
├── templates
│   ├── 404.html
│   ├── 500.html
│   ├── Base.html
│   ├── Home.html
│   ├── Reoccurring.html
│   └── Usersettings.html
└── usersetting
├── admin.py
├── __init__.py
├── __init__.pyc
├── models.py
├── models.pyc
└── views.py
my django.wsgi:
import os
import sys
sys.path.append('/srv/www/quickerhub.com/')
os.environ['PYTHON_EGG_CACHE'] = '/srv/www/quickerhub.com.python-egg'
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
my httpd.conf:
my sites-enabled/quickerhub.com:
WSGIPythonPath /srv/www/quickerhub.com
<VirtualHost *:80>
ServerName quickerhub.com
Alias /static/ /srv/www/quickerhub.com/interest/static/
WSGIScriptAlias / /srv/www/quickerhub.com/interest/django.wsgi
<Directory />
AllowOverride None
Options -Indexes
</Directory>
</VirtualHost>
I feel like everything is pointing to the correct stuff...
EDIT:
Now just getting a 404 file not found
Please help!
Thanks!
I just setup my site www.noobniche.com on Linode using WSGI. Unfortunately I'm not at home to compare my setup, if you're still having problems tonight I can look into it. From memory in my case, I had to enable by adding to sites-enabled and sites-available.
the structure should look something similar to this;
webapps(root directory)
nichesite
static
django_project_name
--> myproject.wsgi
--> settings.py
--> urls.py
--> views.py
manage.py
it seems your .wsgi file is located in your root directory, when it should be located within your django project folder.
So it looks as if you have conflicting settings for WSGIScriptAlias - one in httpd.conf, pointing to the right path for your wsgi file, and one in your sites-enabled file, pointing to the wrong path (/var/ instead of /srv/).
You should remove the one in httpd.conf and move it to sites-enabled/quickerhub.com so that the version there is correctly pointing to /srv/.

Categories

Resources