Error 404 when trying to configure a bottle-enabled web application on Apache / mod_wsgi

I am a beginner programmer. I started using Python and Bottle for a small web application to print the form as well as it does. The real problem is setting up Apache and mod_wsgi , since my knowledge is almost gone.

My problem . I keep getting this error:

Error 404: not found

Sorry, the requested URL / factura / caused an error: not found

In work, they gave me and redirected the address to IP: port; after several days of reading Apache documents and viewing examples over the Internet, I was able to configure so that my VirtualHost does not break other virtual hosts that are already running. The configuration looks like this (based on the deployment section of the bottle tutorial):

 Listen port NameVirtualHost IP:port <VirtualHost IP:port> ServerName IP:port WSGIDaemonProcess factura processes=1 threads=5 WSGIScriptAlias / /var/www/factura/app.wsgi <Directory /var/www/factura> WSGIProcessGroup factura WSGIApplicationGroup %{GLOBAL} Order deny,allow Allow from all </Directory> </VirtualHost> 

My app.wsgi almost the same as in the "Deploying Bottle Tutorial" section. I added the line sys.stdout = sys.stderr :

 import sys, os, bottle # Change working directory so relative paths (and template lookup) work again sys.path = ['/var/www/factura'] + sys.path os.chdir(os.path.dirname(__file__)) # Error output redirect # Exception KeyError in 'threading' module sys.stdout = sys.stderr import factura application = bottle.default_app() 

Here is some python code that is associated with Bottle:

 from lib import bottle app = bottle.Bottle() #serves files in folder 'static' @app.route('/static/:path#.+#', name='static') def ... @app.route("/factura") @bottle.view("factura") def ... @app.route("/print_factura", method="POST") def ... 

I read some other questions like this one, but I can't figure out what I am missing. I suppose the problem is in app.wsgi ?

UPDATE

file structure

 /var/www/factura/ ## .py files /views ## here is the web template /static ## .css and .js of template /lib ## package with bottle and peewee source files /data ## inkscape file to play with /bin ## backup stuff in repo, not used in code 

Apache error log only shows

Exception KeyError: KeyError(-1211426160,) in <module 'threading' from '/usr/lib/python2.6/threading.pyc'> ignored is a warning against wsgi / python problems, harmless wsgi issue 197

UPDATE 2
added @app.route("/factura/") notice the slash of the trail that with changing the import of the application from factura import app as application these two made it work together

+4
source share
1 answer

If you create your application explicitly:

 app = bottle.Bottle() 

then you should import it into app.wsgi instead of application = bottle.default_app() :

 from factura import app as application 

But what is important is this. In your WSGI file, you do import bottle , but in the application code file, you do from lib import bottle . As you explained, you have two copies of the โ€œBottleโ€: one is installed on the server, the other in the lib directory.

That's why you got 404 Not Found . You actually worked with one library instance (creating the app ) and then providing Apache to another ( default_app ) from another library instance!

It started working fine when you started returning the correct app .

+3
source

Source: https://habr.com/ru/post/1413556/


All Articles