Michael Merickel
2018-10-15 2b024920847481592b1a13d4006d2a9fa8881d72
commit | author | age
a67838 1 from pyramid.response import Response
c96ca8 2 from pyramid.view import view_config
a67838 3
CM 4 from sqlalchemy.exc import DBAPIError
f9e73e 5
13846e 6 from ..models import MyModel
c96ca8 7
877eeb 8
414b67 9 @view_config(route_name='home', renderer='../templates/mytemplate.jinja2')
818f8c 10 def my_view(request):
a67838 11     try:
414b67 12         query = request.dbsession.query(MyModel)
MM 13         one = query.filter(MyModel.name == 'one').first()
a67838 14     except DBAPIError:
13846e 15         return Response(db_err_msg, content_type='text/plain', status=500)
28cf6b 16     return {'one': one, 'project': '{{project}}'}
23b531 17
a67838 18
414b67 19 db_err_msg = """\
a67838 20 Pyramid is having a problem using your SQL database.  The problem
CM 21 might be caused by one of the following things:
22
23 1.  You may need to run the "initialize_{{project}}_db" script
23b531 24     to initialize your database tables.  Check your virtual
a67838 25     environment's "bin" directory for this script and try to run it.
CM 26
27 2.  Your database server may not be running.  Check that the
28     database server referred to by the "sqlalchemy.url" setting in
29     your "development.ini" file is running.
30
31 After you fix the problem, please restart the Pyramid application to
32 try it again.
33 """