Hello!! I am facing a problem when trying to post data to the database. When asking to send the application data I receive the following: Squashed pyramid.httpexceptions.HTTPNotFound at
http://localhost:6543/mod_plataforma/mod1_plataforma/recepx/$%7Bsave_url%7D. Below is information about my files.
# piprdc/piprdc/routes.py
def includeme(config):
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('modulo_x', '/mod_plataforma')
config.add_route('modulo1', '/mod_plataforma/mod1_plataforma')
config.add_route('modulo2', '/mod_plataforma/mod2_plataforma')
config.add_route('modulo3', '/mod_plataforma/mod3_plataforma')
config.add_route('modulo4', '/mod_plataforma/mod4_plataforma')
config.add_route('modulo5', '/mod_plataforma/mod5_plataforma')
config.add_route('modulo6', '/mod_plataforma/mod6_plataforma')
config.add_route('abcx', '/mod_plataforma/mod1_plataforma/recepx')
config.add_route('add_reg', '/mod_plataforma/mod1_plataforma/recepx/add_reg')
config.add_route('query', '/mod_plataforma/mod1_plataforma/recepx/query')
..............................
#views/default.py
from pyramid.view import view_config
from pyramid.response import Response
from sqlalchemy.exc import SQLAlchemyError, DBAPIError
from pyramid.httpexceptions import HTTPFound
from .. import models
from ..models import Patient
from ..models import get_tm_session
dbsession = get_tm_session
view_config(route_name='add_reg', renderer='piprdc:templates/reg_pacx.jinja2')
def add_reg(request):
save_url = request.route_url('add_reg')
request.route_url('query')
print('RUN')
if request.params:
id=request.params['id']
name=request.params['name']
age=request.params['age']
birth_date=request.params['birth_date']
sex=request.params['sex']
race=request.params['race']
fone=request.params['fone']
address=request.params['address']
cpf=request.params['cpf']
cns=request.params['cns']
patients=Patient(id=id, name=name, age=age, date_birth=date_birth, sex=sex,
race=race, phone=phone, address=address, cpf=cpf, cns=cns)
try:
dbsession.add_reg(patients)
return HTTPFound(location=request.route_url('query'))
except DBAPIError:
return Response("DB ERROR")
else:
print('DO NOT RUN')
return{'save_url': save_url, 'project': 'piprdc'}
........................................
#templates/reg_pacx.jinja2
{% extends "basefull.jinja2" %}
{% block container %}
<html>
<body>
<h1><span class="font-semi-bold">Patient registration</span></h1>
<form action="${save_url}" method="POST">
<p>Patient Id: <input type="Integer" name="id"/> </p>
<p>Patient Name: <input type="text" name="name"/> </p>
<p>Age: <input type="Integer" name="age"/> </p>
<p>Date of birth: <input type="Integer" name="date_birth"/> </p>
<p>Gender: <input type="text" name="sex"/> </p>
<p>Race: <input type="text" name="breed"/> </p>
<p>Phone: <input type="text" name="phone"/> </p>
<p>Address: <input type="text" name="address"/> </p>
<p>CPF: <input type="Integer" name="cpf"/> </p>
<p>CNS: <input type="Integer" name="cns"/> </p>
<p><input type="submit" value="Submit"> </p>
</body>
</html>
{% endblock container %}
................................
#models/__init__.py
from sqlalchemy import engine_from_config
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import configure_mappers
from sqlalchemy_continuum.plugins import Plugin
import zope.sqlalchemy
from .mymodel import Patient # flake8: noqa
configure_mappers()
def get_engine(settings, prefix='sqlalchemy.'):
return engine_from_config(settings, prefix)
def get_session_factory(engine):
factory = sessionmaker()
factory.configure(bind=engine)
return factory
def get_tm_session(session_factory, transaction_manager, request=None):
dbsession = session_factory(info={"request": request})
zope.sqlalchemy.register(
dbsession, transaction_manager=transaction_manager
)
return dbsession
def includeme(config):
settings = config.get_settings()
settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager'
config.include('pyramid_tm')
config.include('pyramid_retry')
# hook to share the dbengine fixture in testing
dbengine = settings.get('dbengine')
if not dbengine:
dbengine = get_engine(settings)
session_factory = get_session_factory(dbengine)
config.registry['dbsession_factory'] = session_factory
def dbsession(request):
dbsession = request.environ.get('app.dbsession')
if dbsession is None:
dbsession = get_tm_session(
session_factory,
request.tm, request=request
config.add_request_method(dbsession, reify=True)
Any help is welcome.