Django No module name found although I already pip install - django

I am using this for push notification and it is okay on my localhost.
https://github.com/jleclanche/django-push-notifications
But when I deploy to server,
I did
pip install django-push-notifications
But in my settings.py, when I add this, it crash and it say server configuration is wrong. How shall I do?
INSTALLED_APPS = (
'push_notifications'
)

Related

How to install the Django-Simple-Blog package into an existing Django project?

I found a similar question, with this reply: "...django-simple-blog is an app, meaning you install it within an existing project."
But I need more explanation. Can someone explain to me how to "install" an app within an existing Django project? And what it means to do so? (I use Pycharm).
Django allows us to add multiple apps.
For eg.: if we want to add multiple social authentications, we can install django-allauth
install a thirdparty app
pip install django-allauth # or any other app you like.
or create a new one
django-admin startapp simpleblog
then we modify our settings.py in our django project.
INSTALLED_APPS = [
...,
'allauth', # add the app name here.
'simpleblog',
]
You can refer following to learn more about Django:
https://docs.djangoproject.com/en/2.1/
https://tutorial.djangogirls.org/en/
https://www.twoscoopspress.com/products/two-scoops-of-django-1-11

using browser-sync with django on docker-compose

I'm doing a project for college and I've never used docker before, I usually use browser-sync when working on static files, but now when I'm using Django on docker-compose (i followed THIS tutorial ), I have no idea how to set it up to work, can anybody give me advice or direct me?
So, i found a solution,
Start by following the tutorial here to set up django with docker-compose, by the end of this you should have a working base django project. then follow the steps below.
How to Use "livereload" With "docker-compose" :
on you host machine, open the command line or the terminal and do :
pip install --upgrade pip
pip install django-livereload-server
pip install psycopg2-binary
PS: i'm using psycopg2 in docker-compose that's why i'm installing it,
if you're using something else, install it instead of psycopg2
Now add to the requirements.txt file (from the tutorial) this line
django-livereload-server
The file should look like this (if you followed the tutorial step by step, you can change according to what db you want to use)
Django==2.0
psycopg2-binary
django-livereload-server
Open the terminal, cd to your projects directory, and do:
docker-compose build
to download the new django-livereload to your docker environment.
Now, you've everything installed,
you need to setup your project to use the django-livereload-server module,
In your project's settings.py
add livereload to INSTALLED_APPS:
INSTALLED_APPS = [
...
'livereload',
...
]
and add the livereload middleware to MIDDLEWARE:
MIDDLEWARE = [
...
'livereload.middleware.LiveReloadScript',
]
and make sure that DEBUG is set to True.
now you can start developing,
open 2 consoles (terminals) in your project's directory
in the first one do :
python manage.py livereload
wait until the server starts, when it's working, leave it running, and in the second terminal do:
docker-compose up
the server in the second terminal is running the django development server, and the server in the first terminal is feeding the first one a livereload.js file, which is used by the django-livereload-server module to inject css, automatically reload html and js when saving, .. etc
PS : make sure the first server (livereload) is working before you launch the second one
i hope this helped !

No module named middleware for django-bouncer

I'm using django-bouncer to make a waiting list in a Django 1.6 app. Unfortunately, when I add 'bouncer.middleware.MembersOnlyMiddleware' to my MIDDLEWARE_CLASSES as required, I get: "ImportError: No module named middleware." I tried going into the Django shell and typing "from bouncer.middleware import MembersOnlyMiddleware," but that received the same error.
What can I do to resolve this problem?
django-bouncer and bouncer are not the same package.
Try to install django-bouncer:
pip install django-bouncer

Issues deploying django-nvd3 charts on heroku

Did any one try to deploy django-nvd3 charts on to Heroku recently with success? I was trying to deploy django application using nvd3 charts on to heroku the whole weekend with no luck. It works perfectly fine in my dev enviornment (ubuntu). However when I try to push it to Heroku, am facing all sorts of errors.
on Dev environment I installed npm (this includes node.js) and later installed bower and finally installed django-bower; as suggested on https://github.com/areski/django-nvd3. I tried different charts and all work okay, with no issues
However, when I was trying to push the code over to Heroku, I was hitting quite a few errors. Fixing one leads to others. I was wondering, if I need to add a package.json (to list npm dependencies like bower) and bower.json (to list bower dependencies like d3, nvd3) files to my repo, in the first place?
I googled a lot for some documentation that gives gun-shot info on this(django, nvd3, bower, npm/node all married together), but couldn't see any
Note: I will try to post heroku logs for more info.
bower.json is given something like:
{
"dependencies": {
"d3": "3.3.6",
"nvd3": "1.1.12-beta"
}
package.json is given something like:
"engines": {
"node": "0.11.11",
"npm": "1.3.25"
},
"dependencies": {
"bower": "1.3.1"
}
Errors I encountered are something like:
1. gunicorn is not recognized - resolved this
2. NameError: Name 'DATABASES' is not defined in settings.py - resolved this
3. django.core.management is not found - resolved this
4. Git error: fatal: HEAD corrupted/ cannot be deployed on to heroku - resolved this
5. listening at localhost 127.0.0.1:8000 - am working on this. I think this is also to do with my DATABASES setting that is pointing at dj_database_url.config(default=['DATABASE_URL'])??
Is there any Git repo with django+nvd3charts that is deployed successfully on to Heroku? Can I have a look at the configuration?
Also looking at https://github.com/areski/django-nvd3; I do not see any bower dependencies or npm dependencies listed here, does it work like this?
Or, can Heroku automatically install npm/bower without package.json and also can it look at settings.py file and by looking at bower dependencies, does Heroku also install those dependencies with out a need for bower.json file to specifically listing d3, nvd3 as dependencies? I suppose its not the case, as far as I could see
Please suggest
I wrote a blog post about this which you find here: https://mattdoesstuff.wordpress.com/2015/04/10/getting-npm-d3-nvd3-django-bower-django-bower-nvd3-and-heroku-to-play-nicely-together/
Use django-nvd3 and django-bower
pip install django-nvd3 django-bower
pip freeze > requirements.txt
git add .
git commit -m "don't forget your requirements.txt!"
Use a multi-buildpack
heroku config:set BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
Use the Node and Python buildpacks together
# ./.buildpacks
https://github.com/heroku/heroku-buildpack-nodejs.git
https://github.com/amanjain/heroku-buildpack-python-with-django-bower.git
Download bower using npm
# ./package.json
{"private": true,"dependencies": {"bower": "1.4.1"}}
User django-bower to collect its assets
# ./bin/post_compile
# install bower components
./manage.py bower_install
Tell django where to find bower
# settings.py
...
import os
APPLICATION_DIR = os.path.dirname(globals()['__file__'])
HEROKU = bool(os.environ.get('DATABASE_URL'))
BOWER_COMPONENTS_ROOT = os.path.join(APPLICATION_DIR, 'components')
# where to find your local bower
BOWER_PATH = '/usr/local/bin/bower'
if HEROKU:
BOWER_PATH = '/app/node_modules/bower/bin/bower'
BOWER_INSTALLED_APPS = (
'd3#3.3.13',
'nvd3#1.7.1',
)
...
Credits
* http://www.rawsrc.com/using-django-bower-on-heroku/
* https://github.com/ddollar/heroku-buildpack-multi.git
* https://github.com/areski/django-nvd3

deploying Django - Dreamhost

I am neewbie with django and I am stuck trying to deploy my project on the server ( a shared Dreamhost server). I have followed the tutorials I found but it doesnt work. My project structure is:
/usr/mydomain.com
- public
* media
* static
- project
* __init__.py
* manage.py
* settings.py
* urls.py
* views.py
- tmp
- django-setup.py
- manage.py
- passenger_wsgi.py
- passenger_wsgi.pyc
It only works on my domain.com/admin, but I have a simple 'hello world' view to try but it isnt showing. I get only an HTTP 404 when I access my domain...
EDIT
I have installed Python 2.7 and Django 1.5 . Now I get a 500 Internal Server Error.
This is how I do it, with Django 1.5, on DreamHost:
A virtualenv dedicated to my project is in ~/virtualenv/myproject
My Django project is in ~/projects/myproject, with setup:
The database file is in the project root, named sqlite3.db
STATIC_ROOT is set to os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'static'), that is, the static directory in the project root.
When the static files are updated in the project, I have to run python manage.py collectstatic
I have per-environment settings in ~/projects/myproject/myproject, named prod_settings.py, beta_settings.py, and so on.
My site is in ~/sites/www.myproject.com, the layout inside:
myproject -- symlink to the Django project
sqlite3.db -- symlink to the database file in the Django project
public/static -- symlink to the STATIC_ROOT defined in the Django project
tmp/restart.txt -- touch this file to have Passenger reload the site settings
passenger_wsgi.py -- the Passenger configuration
Create passenger_wsgi.py like this:
projectname = 'myproject'
virtualenv_root = '/home/jack/virtualenv/' + projectname
import sys
import os
INTERP = os.path.join(virtualenv_root, 'bin', 'python')
if sys.executable != INTERP:
os.execl(INTERP, INTERP, *sys.argv)
sys.path.append(os.path.join(os.getcwd(), projectname))
os.environ['DJANGO_SETTINGS_MODULE'] = projectname + '.prod_settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Create prod_settings.py like this:
from myproject.settings import *
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ADMINS = (('My Project', 'info#myproject.com'), )
MANAGERS = ADMINS
DATABASES = {} # Appropriately for your production environment
SECRET_KEY = "..." # Your secret key
ALLOWED_HOSTS = ["myproject.com", "www.myproject.com"]
For Django 1.4 or earlier, you need to make some minor modifications, but the same idea works. I've been using variations of this setup since Django 1.2.
I setup virtualenv like this:
# install pip and virtualenv in my home directory
easy_install --user pip
pip install --user virtualenv
# create a virtualenv dedicated to my django project
mkdir ~/virtualenv
virtualenv --distribute ~/virtualenv/myproject
# activate the virtualenv, install django and all project dependencies
. ~/virtualenv/myproject/bin/activate
cd ~/projects/myproject
pip install -r requirements.txt
Notice that after activating the virtualenv, you don't need the --user flag anymore when you install packages with pip. When a virtualenv is active, all packages are installed in that virtualenv.
About requirements.txt:
Create it in your development like this: pip freeze > requirements.txt
Edit it, leave only the packages that your project really really needs. It's better to remove too much and add back later as needed.
Note that virtualenv is not necessary, but recommended. You can do without by setting INTERP in your passenger_wsgi.py to /usr/bin/python. virtualenv is useful to have multiple Django sites with different dependencies on the same account. It is also useful when you want to upgrade Django for your site, so that you can test the upgrade on beta.myproject.com without disrupting traffic on your main site.
Finally, if you are using shared hosting, DreamHost support encourages using different user accounts for each website, but I don't know what difference that makes. Be careful with heavy operations, for example large data imports, because if the process uses much memory, it can get killed by DreamHost. The memory ceiling is unspecified, but it's quite low. So if your site needs to do some heavy operations, you need to make such operations fault tolerant, in order to resume after killed.