You should ask this in a Flask discussion group or stackoverflow. This is a sqlalchemy group and most users here have no experience with Flask.
On Friday, August 19, 2022 at 4:13:50 PM UTC-4 nand...@gmail.com wrote: > I am trying to fill up a field in a table database with contents of a text > file, but get None as the response when I run the code. Any assistance will > be appreciated. Here is my code: > > # view function - routes.py > ....... > @app.route('/add_vlans', methods = ['GET', 'POST']) > @login_required > def add_vlans(): > form = AddVlanForm(current_user.routername) > if form.validate_on_submit(): > with open("show_vlans", "r") as vlans: > vlan_output = vlans.read() > rt = Router(raw_vlans=vlan_output) #raw_vlans - field variable > name > db.session.add(rt) > db.session.commit() > return render_template('_show_vlans.html', title='Router Vlans') > > #forms.py > class AddVlanForm(FlaskForm): > raw_vlans = TextAreaField('Router vlan output:', > validators=[Length(min=0, max=140)]) > submit = SubmitField('Get Vlans on Router') > > #templates - router.html > {% extends "base.html" %} > > {% block content %} > > <h1>Router: {{ router.routername }}</h1> > > {% if router.about_router %} <p>About router: {{ router.about_router > }}</p> {% endif %} > > Vlans on {{ router.routername }}<br> > {% for vlan in vlans %} > <ul> > <li>{% include '_vlan.html' %}</li> > </ul> > {% endfor %} > {% if router == current_user %} > <p> <a href="{{ url_for('edit_router') }}"> Edit Router </a> </p> > {% endif %} > <h1> Vlan Configurations </h1> > <a href="{{ url_for('add_vlans') }}"> Show Router Vlans </a> > > <p> {% include '_show_vlans.html' %} </p> > > {% endblock %} > > #sub-template - _show_vlans.html > <table> > <tr> > <td>Vlans on router {{ current_user.routername }}: > <pre>{{ current_user.raw_vlans }}</pre> > </td> > </tr> > </table> > > I get the response: > Vlans on router router20: None > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/f5b7ed8b-4c65-4e5d-a274-f8f8460e96fbn%40googlegroups.com.