I'm getting this error when trying to run project on azure windows server but It's working fine on Ubuntu machine and My Local Windows machine. I have deploy flask project on Apache with mod_wsgi server.
I have already installed the all the required dependencies.
[Thu Feb 18 09:03:58.636970 2021] [wsgi:error] [pid 5724:tid 1120] [client 110.225.67.165:26675] mod_wsgi (pid=5724): Failed to exec Python script file 'C:/Users/user/Desktop/flask/app/src/app.wsgi'.
[Thu Feb 18 09:03:58.636970 2021] [wsgi:error] [pid 5724:tid 1120] [client 110.225.67.165:26675] mod_wsgi (pid=5724): Exception occurred processing WSGI script 'C:/Users/user/Desktop/flask/app/src/app.wsgi'.
[Thu Feb 18 09:03:58.636970 2021] [wsgi:error] [pid 5724:tid 1120] [client 110.225.67.165:26675] Traceback (most recent call last):\r
[Thu Feb 18 09:03:58.636970 2021] [wsgi:error] [pid 5724:tid 1120] [client 110.225.67.165:26675] File "C:/Users/user/Desktop/flask/app/src/app.wsgi", line 4, in <module>\r
[Thu Feb 18 09:03:58.636970 2021] [wsgi:error] [pid 5724:tid 1120] [client 110.225.67.165:26675] from wsgi import app as application\r
[Thu Feb 18 09:03:58.636970 2021] [wsgi:error] [pid 5724:tid 1120] [client 110.225.67.165:26675] File "C:\\Users\\user\\Desktop\\flask\\app\\src\\wsgi.py", line 6, in <module>\r
[Thu Feb 18 09:03:58.636970 2021] [wsgi:error] [pid 5724:tid 1120] [client 110.225.67.165:26675] from server import app\r
[Thu Feb 18 09:03:58.636970 2021] [wsgi:error] [pid 5724:tid 1120] [client 110.225.67.165:26675] File "C:\\Users\\user\\Desktop\\flask\\app\\src\\server.py", line 10, in <module>\r
[Thu Feb 18 09:03:58.636970 2021] [wsgi:error] [pid 5724:tid 1120] [client 110.225.67.165:26675] from azure_portal.blob_storage import BlobStorage\r
[Thu Feb 18 09:03:58.636970 2021] [wsgi:error] [pid 5724:tid 1120] [client 110.225.67.165:26675] File "C:\\Users\\user\\Desktop\\flask\\app\\src\\azure_portal\\blob_storage.py", line 5, in <module>\r
[Thu Feb 18 09:03:58.636970 2021] [wsgi:error] [pid 5724:tid 1120] [client 110.225.67.165:26675] from azure.storage.blob import BlobServiceClient\r
[Thu Feb 18 09:03:58.636970 2021] [wsgi:error] [pid 5724:tid 1120] [client 110.225.67.165:26675] ModuleNotFoundError: No module named 'azure.storage'\r
Please help me to resolve the issue. It would be very helpful for me.
Are you sure that azure.storage is installed on the machine?
Please install it before you run your project:
script: pip install azure-storage
Try pip list to see what all modules are installed on your machine.
Also, see that, the version which is used by your code, is installed on your machine.
I deploy flask with apache on CentOS7
And I want Oracle database to insert or select when user access.
So I install cx_Oracle
pip install cx_Oracle
And run flask on virtual env.
flask run
It work with no error.
But I access to localhost:80 using apache, It occur Internal Server Error 500.
In error_log
[Fri Oct 23 09:12:34.623473 2020] [mpm_prefork:notice] [pid 475] AH00170: caught SIGWINCH, shutting down gracefully
[Fri Oct 23 09:12:35.678302 2020] [lbmethod_heartbeat:notice] [pid 510] AH02282: No slotmem from mod_heartmonitor
[Fri Oct 23 09:12:35.681622 2020] [mpm_prefork:notice] [pid 510] AH00163: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations
[Fri Oct 23 09:12:35.681665 2020] [core:notice] [pid 510] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Fri Oct 23 09:12:38.074902 2020] [:error] [pid 513] [client 172.17.0.1:33640] mod_wsgi (pid=513): Target WSGI script '/var/www/hitme/wsgi.py' cannot be loaded as Python module.
[Fri Oct 23 09:12:38.074946 2020] [:error] [pid 513] [client 172.17.0.1:33640] mod_wsgi (pid=513): Exception occurred processing WSGI script '/var/www/hitme/wsgi.py'.
[Fri Oct 23 09:12:38.074973 2020] [:error] [pid 513] [client 172.17.0.1:33640] Traceback (most recent call last):
[Fri Oct 23 09:12:38.074994 2020] [:error] [pid 513] [client 172.17.0.1:33640] File "/var/www/hitme/wsgi.py", line 10, in <module>
[Fri Oct 23 09:12:38.075058 2020] [:error] [pid 513] [client 172.17.0.1:33640] from app import app as application
[Fri Oct 23 09:12:38.075070 2020] [:error] [pid 513] [client 172.17.0.1:33640] File "/var/www/hitme/app/__init__.py", line 4, in <module>
[Fri Oct 23 09:12:38.075138 2020] [:error] [pid 513] [client 172.17.0.1:33640] import cx_Oracle
[Fri Oct 23 09:12:38.075162 2020] [:error] [pid 513] [client 172.17.0.1:33640] ImportError: No module named cx_Oracle
I followed this article for deploy flask with apache.
https://dev.to/sm0ke/flask-deploy-with-apache-on-centos-minimal-setup-2kb7
and install cx_Oracle and I copied it where I thought I needed it.
Here my tree
/etc/httpd/modules/
|-cx_Oracle.cpython-36m-x86_64-linux-gnu.so
|-cx_Oracle-8.0.1.dist-info
/var/www/hitme/lib/python3.6/site-packages
|-cx_Oracle.cpython-36m-x86_64-linux-gnu.so
|-cx_Oracle-8.0.1.dist-info
/usr/local/lib/python3.6/site-packages
|-cx_Oracle.cpython-36m-x86_64-linux-gnu.so
|-cx_Oracle-8.0.1.dist-info
But it still gives the error.
Is there any other way?
Ensure that the required Oracle Instant Client is installed to the Apache user by downloading
https://download.oracle.com/otn_software/linux/instantclient/199000/instantclient-basic-linux.x64-19.9.0.0.0dbru.zip
and unzip ut to a folder Apache user owns or is accessible for read and execute - lets say
/apache/oracle
After that, ensure PATH, ORACLE_HOME and LD_LIBRARY_PATH ist set properly as Apache User - i.e.
export ORACLE_HOME=/apache/oracle
export PATH=$PATH:$ORACLE_HOME
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
If you start Apache as service then you may need to set the variables to root or user who starts apache.
I have a flask application running on apache server in the Linux box(ec2 instance), which calls the python script that does the work of moving the files from s3 to snowflake. The script works fine if executed directly. It throws the below error for the snowflake's ingest python module when trying to host it on apache using virtualhost and mod_wsgi. The module is installed in the default site packages.
Apache server version: 2.4.41
Python Version: 3.7
snowflake: snowflake_connector_python-2.1.3-py3.7-nspkg.pth
OS: AMAZON linux 2
Below is the apache error log, when i try to restart:
[Fri Jan 10 15:47:53.703083 2020] [:error] [pid 19755] [remote 67.79.202.36:20] mod_wsgi (pid=19755): Target WSGI script '/var/www/FLASKAPPS/snowflakeingestapp/snowflakeingestapp.wsgi' cannot be loaded as Python module.
[Fri Jan 10 15:47:53.703113 2020] [:error] [pid 19755] [remote 67.79.202.36:20] mod_wsgi (pid=19755): Exception occurred processing WSGI script '/var/www/FLASKAPPS/snowflakeingestapp/snowflakeingestapp.wsgi'.
[Fri Jan 10 15:47:53.703129 2020] [:error] [pid 19755] [remote 67.79.202.36:20] Traceback (most recent call last):
[Fri Jan 10 15:47:53.703142 2020] [:error] [pid 19755] [remote 67.79.202.36:20] File "/var/www/FLASKAPPS/snowflakeingestapp/snowflakeingestapp.wsgi", line 4, in
[Fri Jan 10 15:47:53.703176 2020] [:error] [pid 19755] [remote 67.79.202.36:20] from snowflakeingestapp import app as application
[Fri Jan 10 15:47:53.703181 2020] [:error] [pid 19755] [remote 67.79.202.36:20] File "/var/www/FLASKAPPS/snowflakeingestapp/init.py", line 6, in
[Fri Jan 10 15:47:53.703206 2020] [:error] [pid 19755] [remote 67.79.202.36:20] import snowflake_ingest
[Fri Jan 10 15:47:53.703210 2020] [:error] [pid 19755] [remote 67.79.202.36:20] File "/var/www/FLASKAPPS/snowflakeingestapp/snowflake_ingest/init.py", line 1, in
[Fri Jan 10 15:47:53.703225 2020] [:error] [pid 19755] [remote 67.79.202.36:20] import ingest_ecomm_json_snowpipe
[Fri Jan 10 15:47:53.703230 2020] [:error] [pid 19755] [remote 67.79.202.36:20] File "/var/www/FLASKAPPS/snowflakeingestapp/snowflake_ingest/ingest_ecomm_json_snowpipe.py", line 20, in
[Fri Jan 10 15:47:53.703296 2020] [:error] [pid 19755] [remote 67.79.202.36:20] from snowflake.ingest import SimpleIngestManager
[Fri Jan 10 15:47:53.703300 2020] [:error] [pid 19755] [remote 67.79.202.36:20] File "/usr/local/lib/python3.7/site-packages/snowflake/ingest/init.py", line 1, in
[Fri Jan 10 15:47:53.703315 2020] [:error] [pid 19755] [remote 67.79.202.36:20] from .simple_ingest_manager import SimpleIngestManager, StagedFile
[Fri Jan 10 15:47:53.703342 2020] [:error] [pid 19755] [remote 67.79.202.36:20] File "/usr/local/lib/python3.7/site-packages/snowflake/ingest/simple_ingest_manager.py", line 65
[Fri Jan 10 15:47:53.703345 2020] [:error] [pid 19755] [remote 67.79.202.36:20] def init(self, account: Text, user: Text, pipe: Text, private_key: Text,
[Fri Jan 10 15:47:53.703347 2020] [:error] [pid 19755] [remote 67.79.202.36:20] ^
[Fri Jan 10 15:47:53.703350 2020] [:error] [pid 19755] [remote 67.79.202.36:20] SyntaxError: invalid syntax
It looks like when you're executing this from mod_wsgi, you're using Python 2 instead of Python 3. The error message you see is happening because Snowflake's simple ingest manager uses type hints (via the typing module), which are not available in Python 2.
Here's a simple fragment that fails with the same error in Python 2 but succeeds in Python 3:
from typing import Text
def foo(bar: Text):
print(bar)
foo('huh')
|--------FlaskApp
|----------------FlaskApp
|----------------__init__.py
|----------------view.py
|----------------models.py
|----------------db_create.py
|-----------------------static
|-----------------------templates
|-----------------------venv
|-----------------------__init__.py
|----------------flaskapp.wsgi
this is my modules and folder layout i have a import problem in init i have db = sqlalchemy im trying to import db to views.py, models.py and db_create.py but im getting all kinds of importing errors because im not importing thr proper way now my question is if i want to import db to the modules i specified how would i do it without getting a error
some of the code importing db
models.py
from FlaskApp import db
class UserInfo(db.Model):
__tablename_ = 'user_info'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True)
email = db.Column(db.String(80), unique=True)
password = db.Column(db.String(100), nullable=False)
posts = relationship('UserPosts', backref='posts')
def __init__(self, username, email, password):
self.username = username
self.email = email
self.password = password
def __repr__(self):
return '{}-{}'.format(self.username, self.email)
views.py
from FlaskApp import db
#app.route('/')
#login_required
def home():
user = db.session.query(UserInfo).all()
return render_template('home.html', user=user)
__init__.py
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy(app)
tail /var/log/apache2/error.log
[Tue Oct 11 04:17:20.925573 2016] [wsgi:error] [pid 5049:tid 139870897813248] [client 174.58.31.189:55884] Traceback (most recent call last):, referer: http://localhost/
[Tue Oct 11 04:17:20.925618 2016] [wsgi:error] [pid 5049:tid 139870897813248] [client 174.58.31.189:55884] File "/var/www/FlaskApp/flaskapp.wsgi", line 14, in <module>, referer: http://localhost/
[Tue Oct 11 04:17:20.925626 2016] [wsgi:error] [pid 5049:tid 139870897813248] [client 174.58.31.189:55884] from FlaskApp import app as application, referer: http://localhost/
[Tue Oct 11 04:17:20.925638 2016] [wsgi:error] [pid 5049:tid 139870897813248] [client 174.58.31.189:55884] File "/var/www/FlaskApp/FlaskApp/__init__.py", line 4, in <module>, referer: http://localhost/
[Tue Oct 11 04:17:20.925644 2016] [wsgi:error] [pid 5049:tid 139870897813248] [client 174.58.31.189:55884] import FlaskApp.main, referer: http://localhost/
[Tue Oct 11 04:17:20.925653 2016] [wsgi:error] [pid 5049:tid 139870897813248] [client 174.58.31.189:55884] File "/var/www/FlaskApp/FlaskApp/main.py", line 7, in <module>, referer: http://localhost/
[Tue Oct 11 04:17:20.925658 2016] [wsgi:error] [pid 5049:tid 139870897813248] [client 174.58.31.189:55884] from models import UserInfo, referer: http://localhost/
[Tue Oct 11 04:17:20.925668 2016] [wsgi:error] [pid 5049:tid 139870897813248] [client 174.58.31.189:55884] File "/var/www/FlaskApp/FlaskApp/models.py", line 2, in <module>, referer: http://localhost/
[Tue Oct 11 04:17:20.925673 2016] [wsgi:error] [pid 5049:tid 139870897813248] [client 174.58.31.189:55884] from FlaskApp import db, referer: http://localhost/
[Tue Oct 11 04:17:20.925707 2016] [wsgi:error] [pid 5049:tid 139870897813248] [client 174.58.31.189:55884] ImportError: cannot import name 'db', referer: http://localhost/
my goal is not just to solve one error is to be able to import the right way from now on
This is actually the most painful moment for a Flask learner. Basically, your FlaskApp is dependent on FlaskApp.main then FlaskApp.models and then back to FlaskApp which create a perfect case of circular dependency.
Here's the way which I think is elegant and pythonic, by attaching the db variable to app in __init__.py:
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy(app)
app.db = db
with app.app_context():
import FlaskApp.main
In main.py:
from flask import current_app as app
from .models import UserInfo
#app.route('/')
#login_required
def home():
user = app.db.session.query(UserInfo).all()
return render_template('home.html', user=user)
In models.py:
from flask import current_app as app
db = app.db
class UserInfo(db.Model):
__tablename_ = 'user_info'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True)
email = db.Column(db.String(80), unique=True)
password = db.Column(db.String(100), nullable=False)
posts = relationship('UserPosts', backref='posts')
def __init__(self, username, email, password):
self.username = username
self.email = email
self.password = password
def __repr__(self):
return '{}-{}'.format(self.username, self.email)
Then you can use app.db or current_app.db inside of any functions/methods in your application and don't need to worry about the circular dependency.
got this after using the above answer
RuntimeError: Working outside of application context. This typically means that you attempted to use functionality that needed to interface with the current application object in a way. To solve this set up an application context with app.app_context(). See the documentation for more information.
tail -n 40 /var/log/apache2/error.log
[Wed Oct 12 00:20:02.315500 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] import FlaskApp.main
[Wed Oct 12 00:20:02.315510 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] File "/var/www/FlaskApp/FlaskApp/main.py", line 2, in <module>
[Wed Oct 12 00:20:02.315516 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] from .models import UserInfo
[Wed Oct 12 00:20:02.315526 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] File "/var/www/FlaskApp/FlaskApp/models.py", line 7, in <module>
[Wed Oct 12 00:20:02.315532 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] db = app.db
[Wed Oct 12 00:20:02.315542 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] File "/usr/local/lib/python3.5/dist-packages/werkzeug/local.py", line 343, in __getattr__
[Wed Oct 12 00:20:02.315547 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] return getattr(self._get_current_object(), name)
[Wed Oct 12 00:20:02.315557 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] File "/usr/local/lib/python3.5/dist-packages/werkzeug/local.py", line 302, in _get_current_object
[Wed Oct 12 00:20:02.315563 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] return self.__local()
[Wed Oct 12 00:20:02.315573 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] File "/usr/local/lib/python3.5/dist-packages/flask/globals.py", line 51, in _find_app
[Wed Oct 12 00:20:02.315579 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] raise RuntimeError(_app_ctx_err_msg)
[Wed Oct 12 00:20:02.315611 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] RuntimeError: Working outside of application context.
[Wed Oct 12 00:20:02.315620 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784]
[Wed Oct 12 00:20:02.315628 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] This typically means that you attempted to use functionality that needed
[Wed Oct 12 00:20:02.315634 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] to interface with the current application object in a way. To solve
[Wed Oct 12 00:20:02.315641 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] this set up an application context with app.app_context(). See the
[Wed Oct 12 00:20:02.315648 2016] [wsgi:error] [pid 19327:tid 139821662463744] [client 174.58.31.189:51784] documentation for more information.
[Wed Oct 12 00:20:02.813916 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] mod_wsgi (pid=19326): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., referer: http://localhost/
[Wed Oct 12 00:20:02.814030 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] mod_wsgi (pid=19326): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'., referer: http://localhost/
[Wed Oct 12 00:20:02.814917 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] Traceback (most recent call last):, referer: http://localhost/
[Wed Oct 12 00:20:02.814972 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] File "/var/www/FlaskApp/flaskapp.wsgi", line 14, in <module>, referer: http://localhost/
[Wed Oct 12 00:20:02.814981 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] from FlaskApp import app as application, referer: http://localhost/
[Wed Oct 12 00:20:02.814993 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] File "/var/www/FlaskApp/FlaskApp/__init__.py", line 4, in <module>, referer: http://localhost/
[Wed Oct 12 00:20:02.814998 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] import FlaskApp.main, referer: http://localhost/
[Wed Oct 12 00:20:02.815008 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] File "/var/www/FlaskApp/FlaskApp/main.py", line 2, in <module>, referer: http://localhost/
[Wed Oct 12 00:20:02.815014 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] from .models import UserInfo, referer: http://localhost/
[Wed Oct 12 00:20:02.815024 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] File "/var/www/FlaskApp/FlaskApp/models.py", line 7, in <module>, referer: http://localhost/
[Wed Oct 12 00:20:02.815029 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] db = app.db, referer: http://localhost/
[Wed Oct 12 00:20:02.815040 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] File "/usr/local/lib/python3.5/dist-packages/werkzeug/local.py", line 343, in __getattr__, referer: http://localhost/
[Wed Oct 12 00:20:02.815046 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] return getattr(self._get_current_object(), name), referer: http://localhost/
[Wed Oct 12 00:20:02.815055 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] File "/usr/local/lib/python3.5/dist-packages/werkzeug/local.py", line 302, in _get_current_object, referer: http://localhost/
[Wed Oct 12 00:20:02.815061 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] return self.__local(), referer: http://localhost/
[Wed Oct 12 00:20:02.815071 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] File "/usr/local/lib/python3.5/dist-packages/flask/globals.py", line 51, in _find_app, referer: http://localhost/
[Wed Oct 12 00:20:02.815077 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] raise RuntimeError(_app_ctx_err_msg), referer: http://localhost/
[Wed Oct 12 00:20:02.815107 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] RuntimeError: Working outside of application context., referer: http://localhost/
[Wed Oct 12 00:20:02.815114 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] , referer: http://localhost/
[Wed Oct 12 00:20:02.815118 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] This typically means that you attempted to use functionality that needed, referer: http://localhost/
[Wed Oct 12 00:20:02.815123 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] to interface with the current application object in a way. To solve, referer: http://localhost/
[Wed Oct 12 00:20:02.815139 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] this set up an application context with app.app_context(). See the, referer: http://localhost/
[Wed Oct 12 00:20:02.815143 2016] [wsgi:error] [pid 19326:tid 139821670856448] [client 174.58.31.189:51786] documentation for more information., referer: http://localhost/
I'm new to Python, so please bear with me.
I am attempting to create a file in which to store my configuration settings in a Flask project. However, I seem to be getting errors when I attempt to import the file.
Here's my configuration file (location: app/config.py):
database_uri = 'something here'
secret_key = something here"
And here's where I'm using it (location: app/models.py):
from app import config
...
app.config['SQLALCHEMY_DATABASE_URI'] = config.database_uri
However, I seem to be getting this error when launching the application:
[Sat Aug 08 19:00:15.539773 2015] [:error] [pid 29784] [client 188.183.57.54:64122] mod_wsgi (pid=29784): Target WSGI script '/var/www/pwforum/pwforum.wsgi' cannot be loaded as Python module.
[Sat Aug 08 19:00:15.540014 2015] [:error] [pid 29784] [client 188.183.57.54:64122] mod_wsgi (pid=29784): Exception occurred processing WSGI script '/var/www/pwforum/pwforum.wsgi'.
[Sat Aug 08 19:00:15.540146 2015] [:error] [pid 29784] [client 188.183.57.54:64122] Traceback (most recent call last):
[Sat Aug 08 19:00:15.540250 2015] [:error] [pid 29784] [client 188.183.57.54:64122] File "/var/www/pwforum/pwforum.wsgi", line 7, in <module>
[Sat Aug 08 19:00:15.540448 2015] [:error] [pid 29784] [client 188.183.57.54:64122] from app import app as application
[Sat Aug 08 19:00:15.540537 2015] [:error] [pid 29784] [client 188.183.57.54:64122] File "/var/www/pwforum/app/__init__.py", line 12, in <module>
[Sat Aug 08 19:00:15.540685 2015] [:error] [pid 29784] [client 188.183.57.54:64122] from app import views, models
[Sat Aug 08 19:00:15.540773 2015] [:error] [pid 29784] [client 188.183.57.54:64122] File "/var/www/pwforum/app/views.py", line 3, in <module>
[Sat Aug 08 19:00:15.541061 2015] [:error] [pid 29784] [client 188.183.57.54:64122] from app.models import db, User, Category, Topic, Post
[Sat Aug 08 19:00:15.541154 2015] [:error] [pid 29784] [client 188.183.57.54:64122] File "/var/www/pwforum/app/models.py", line 11, in <module>
[Sat Aug 08 19:00:15.541333 2015] [:error] [pid 29784] [client 188.183.57.54:64122] app.config['SQLALCHEMY_DATABASE_URI'] = config.database_uri
[Sat Aug 08 19:00:15.541413 2015] [:error] [pid 29784] [client 188.183.57.54:64122] AttributeError: 'module' object has no attribute 'database_uri'
Your config file should look like this:
SQLALCHEMY_DATABASE_URI = '<your-db-driver>://<user>:<pw>#<db-url>'
SECRET_KEY = '<your-very-secret-key>'
Then you can do:
app = Flask(__name__)
app.config.from_object('config')