Forums

Building a live pyramid web application

So I have been working on a pyramid project for quite a while now, and recently started to think about pushing it to a live server. Pythonanywhere seemed like a valid option.

Now, to put it out, I am not a very experienced programmer and do not understand everything as well as I probably should.

My project currently contains an app.py file with the pyramid configurations and route settings, then I have a views.py file with different functions. Additionally I have a HTML- template connected to the first view.

I have tried looking at a very basic level guide on how to run pyramid on pythonanywhere, but I haven't found anything useful yet.

If anybody knows a good guide on how to approach this, please give a link to that. If not, can someone explain how to run a very basic pyramid web app on pythonanywhere?

Thank you!

Create a "manually configured webapp" and put somethign like this in the wsgi file:

import os
import sys

# add your project directory to the sys.path
project_home = u'/home/<your_username>/<directory where your pyramid code is>'
if project_home not in sys.path:
    sys.path.append(project_home)
from pyramid.paster import get_app, setup_logging
ini_path = '/home/<your_username>/<directory where your pyramid code is>/<path to your ini file>'
setup_logging(ini_path)
application = get_app(ini_path, 'main')

Hey, thanks for the response!

Im not very familiar with the Pyramid .ini files. I created my local project just by installing pyramid and creating the app itself. I took a look at the pyramid folder and found 2 ini files: development.ini_tmpl and production.ini_tmpl. Are these the right ones? Should I remove the tmpl - ending? So my ini file would be development.ini.

This is what was inside the file:

> [app:main] use = egg:{{project}}
> 
> pyramid.reload_templates = true pyramid.debug_authorization = false
> pyramid.debug_notfound = false pyramid.debug_routematch = false
> pyramid.debug_templates = true pyramid.default_locale_name = en
> pyramid.includes = pyramid_debugtoolbar
> 
> [server:main] use = egg:pyramid#wsgiref listen = *:6543
> 
> # Begin logging configuration
> 
> [loggers] keys = root, {{package_logger}}
> 
> [handlers] keys = console
> 
> [formatters] keys = generic
> 
> [logger_root] level = INFO handlers = console
> 
> [logger_{{package_logger}}] level = DEBUG handlers = qualname =
> {{package}}
> 
> [handler_console] class = StreamHandler args = (sys.stderr,) level =
> NOTSET formatter = generic
> 
> [formatter_generic] format = %(asctime)s %(levelname)-5.5s
> [%(name)s][%(threadName)s] %(message)s
> 
> # End logging configuration

I now did what you suggested. However I am still getting an error when trying to run the web-app. It only says Error Code: Unhandled Exception, and there is nothing in the error logs.

This is my very simple Pyramid code:

> from waitress import serve from pyramid.config import Configurator
> from pyramid.response import Response
> 
> 
> def hello_world(request):
>     print('Incoming request')
>     return Response('<body><h1>Hello World!</h1></body>')
> 
> 
> if __name__ == '__main__':
>     with Configurator() as config:
>         config.add_route('hello', '/')
>         config.add_view(hello_world, route_name='hello')
>         app = config.make_wsgi_app()
>     serve(app, host='0.0.0.0', port=6543)

And finally the WSGI:

import sys

# add your project directory to the sys.path
project_home = u'/home/vtoivonen/pyramidtest/hello.py'
if project_home not in sys.path:
    sys.path.append(project_home)
from pyramid.paster import get_app, setup_logging
ini_path = '/home/vtoivonen/pyramidtest/config/development.ini'
setup_logging(ini_path)
application = get_app(ini_path, 'main')

I am kind of lost here, would really appreciate more help!

looking at your error log, I do see a lot of errors. Are you sure you are looking at the right log/looking at the right error? (at the bottom)

Oh right, just noticed they are at the bottom instead. Can't really make any use of the errors, since my problem is mainly that my WSGI and .ini files are messed up, and I have no idea how to set them up correctly. Is there any simple guide on how to deploy a basic pyramid app on pythonanywhere? I only found complex guides that I cannot make use of.

If you take your configurator stuff in your pyramid code file, and just let the wsgi.py have access to

application = config.make_wsgi_app()

I think that could possibly work/you may not need a .ini file?