default.py 1.1KB

12345678910111213141516171819202122232425262728293031323334
  1. from pyramid.response import Response
  2. from pyramid.view import view_config
  3. from sqlalchemy.exc import DBAPIError
  4. from ..models import MyModel
  5. @view_config(route_name='home', renderer='../templates/mytemplate.jinja2')
  6. def my_view(request):
  7. try:
  8. query = request.dbsession.query(MyModel)
  9. one = query.filter(MyModel.name == 'one').first()
  10. except DBAPIError:
  11. return Response(db_err_msg, content_type='text/plain', status=500)
  12. return {'one': one, 'project': 'tracim'}
  13. db_err_msg = """\
  14. Pyramid is having a problem using your SQL database. The problem
  15. might be caused by one of the following things:
  16. 1. You may need to run the "initialize_tracim_db" script
  17. to initialize your database tables. Check your virtual
  18. environment's "bin" directory for this script and try to run it.
  19. 2. Your database server may not be running. Check that the
  20. database server referred to by the "sqlalchemy.url" setting in
  21. your "development.ini" file is running.
  22. After you fix the problem, please restart the Pyramid application to
  23. try it again.
  24. """