Flask UWSGI ModuleNotFound - flask

I have a Flask application that I'm trying to configure for a production environment. So far, during testing python app.py inside of a virtualenv works fine.
However, I'm beginning to configure the application to begin using UWSGI. When I attempt to start the Flask app using
$ uwsgi -s /tmp/myapplication.sock --manage-script-name --mount /myapplication=app:app
--virtualenv /path/to/my/venv
I get a
ModuleNotFoundError: No module named 'flask_httpauth'
I was wondering if anyone has experience w/ that authentication module and if they have any advice on what I should do. I'm unsure of why the development server starts without an issue, but the uwsgi server (that I pass the same virtualenv that's used for the dev server) runs into import issues

I was able to resolve this issue by setting the home path to my virtualenv directory (.venv in my case):
# uwsgi.ini
home = /Users/floatingrock/Desktop/projects/google_v2/.venv/
If you're wondering, I got the full path using pwd.

Related

Serve Flask application with GUnicorn on Localhost

I am a noob in this area so please bear with my dumb questions.
I have a Flask application and I want to run that with GUnicorn on my localhost. I looked on Google but almost every tutorial requires a domain name and there isn't much documentation for running it on a mac.
Please tell how can I run the app with GUnicorn on my mac?
I want to use https for the secure communication so how can I change the configuration of Gunicorn to do so?
Any help will be great.
Cheers
Since you want to run it on your localhost you don't need any domain name. You just have to run Python file where you have configured your flask app on your terminal and then you will get a port number where application will be running on your local machine.
Steps to run app
Change your current directory of your terminal to directory where your project is present, using
cd <your directory address>
Now run your app using
python ./<file_name>.Py
Note: If you have both Python 2 and Python 3 installed (Your machine comes with a version of Python 2 but you can install Python 3 as well), you should run
python3 <file_name>.py
Even if you want to deploy on web on a server without your domain name for free you can do it using heroku or any other service as you like.
Running a Flask application on gunicorn is quite simple:
gunicorn <file_name>:app
Gunicorn provides many command-line options – see gunicorn -h. For example, to run a Flask application with 4 worker processes (-w 4) binding to localhost on port 4000 (-b 127.0.0.1:4000):
gunicorn -w 4 -b 127.0.0.1:4000 <file_name>:app

how to use supervisor when I should running a celery in django which is in a virtualenv?

Yesterday, I deployed a Django project with nginx, uwsgi, celery, supervisor. All seemed fine.
But I have some questions come about it.
Generally saying, this time i deployed a Django project and used the local python installation, but if i must use the python in a virtual environment, what should i do ?
For example, i code some task (with django-celery) which will be used by django site to control some timing task, and the django project based python3 (the python3 environment is in a virtualenv).
So the celery should be used by python3, which is in a virtualenv, not the local python environment.
It means that if i set the command in supervisor as:
command=python ****/manage.py celery
then an error would occur.
The uwsgi has some setting about this, where I can set the path of virtualenv.
But in supervisor, I could not see some setting or some way to use the virtualenv.
Help please?
Include the path to your virtual environment in the command:
command=/path/to/venv/bin/python celery worker

How do I setup memcached for a django app on nitrous.io

I'm trying to setup a django app with memcached. I have the app working via virtualenv on nitrous.io without memcached.
I ran parts install memcached which worked fine. python-memcached is also installed in the virtualenv. I tried running:
memcached -d -m memory -s $HOME/memcached.sock -P $HOME/memcached.pid
which I do on my production server. But I got this error:
failed to set rlimit for open files. Try starting as root or requesting smaller maxconns value.
The user rights and whatnot are a little out of my scope of knowledge?
You should always use parts start memcached to run the service on Nitrous.IO.
To change the configuration for the memcached package, edit /home/action/.parts/etc/memcached.conf.

How to debug Two Scoops of Django project skeleton on production server running gunicorn

I don't get a traceback from the Two Scoops project (https://github.com/twoscoops/django-twoscoops-project).
I'm running a Ubuntu 12.04 production server on Virtualbox and I setup gunicorn. I'm trying to learn how to setup a production server so I can host it on Digital Ocean. So far, I've been able to get gunicorn to run by typing this in /myproject/myproject/ (the same directory as my manage.py):
gunicorn wsgi # run this in the same directory as wsgi.py
Then I type:
curl localhost:8000
But I only get back:
<\h1\> Whoops! <\h1>
I did the following:
export DJANGO_SETTINGS_MODULE=myproject.settings.production
But I still get the same "whoops" page. Any thoughts on how I can get the Python traceback or Django debug page to work?
I figured out how to turn on the debugging in a production setup.
You have to goto /settings/base.py and set DEBUG = True. It was False by default.

Installing, configuring and developing for django on ubuntu 10.10 server

I wanted to start getting into developing with Django, however, I am unable to figure out how to make it work. I have installed apache2, I have tried many tutorials on configuring apache to run Django, but I just do not understand how it all works together. Can someone give me a dummies guide on how to install it, how things work, and why?
The best way to link between Django and Apache is using WSGI. You will need to install the mod_wsgi apache module to do this.
Next step: modify the apache configuration file to designate where you want the root of your django website.
WSGIScriptAlias / /path/to/mysite/apache/myApp.wsgi
Next, you should create the wsgi file. This is what initializes your django application. An example wsgi file looks like this
import sys
import os
sys.path.insert(0,os.path.normpath(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0,'/path/to/directory/containing/application')
import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'twitmycity.settings'
application = django.core.handlers.wsgi.WSGIHandler()
Once you have this, restart apache
sudo /etc/init.d/apache2 restart
Now, point your browser to the root directory where you established the wsgi handler. This should bring you to the root to your django application. I hope this helps!
Also note, when you make a change to your application, you need to refresh the modified time on the wsgi file to prevent wsgi from just using a cache version of the django application. To do this, execute
touch myApp.wsgi