Show and update data in form with Sqlalchemy Flask
up vote
0
down vote
favorite
I'm here with a question. There's a problem. The user is registering and filling out forms after logging in to the administration panel. After filling out the forms, the save button is pressed and saved in the database. The problem starts here. That is, after pressing the Save button, it redirects to the same page. At this stage, I want the user to have the information that is saved in the database in the form and to update the database when it makes a change. I didn't understand how to do that.
Python Code :
def admin():
form = KisiForm(request.form)
if request.method == "POST":
gelinAdi = form.gelinAdi.data
gelinFoto = request.files['gelinFoto'] if request.files.get('gelinFoto') else None
gelinBio = form.gelinBio.data
gfilename = False
if gelinFoto:
yol = app.config['UPLOAD_FOLDER'] + whuser
yol = yol + '/profil'
gfilename = secure_filename(gelinFoto.filename)
gelinFoto.save(os.path.join(yol, gfilename))
if gfilename:
kisi = bilgi(gelinAdi = gelinAdi, gelinFoto = gfilename, gelinBio = gelinBio)
db.session.add(kisi)
db.session.commit()
return redirect(url_for("admin"))
return render_template("admin/index.html",form=form)
def upload():
form = albumf(request.form)
if request.method == 'POST' and 'files' in request.files:
for f in request.files.getlist('files'):
files = form.files.data
username = session["username"]
url=app.config['UPLOAD_FOLDER']+username
f.save(os.path.join(url, f.filename))
user = users.query.filter_by(username=username).first()
fotoo = foto(whfoto = user, foto=f.filename)
db.session.add(fotoo)
db.session.commit()
return render_template('/admin/galeri.html',form=form)
return render_template('/admin/galeri.html',form=form)
HTML Code (admin Panel):
<li class="col-xs-6 col-lg-6">
<div class="form-group">
<label for="exampleInputEmail1">Gelin İsmi : </label>{{ render_field(form.gelinAdi,class="form-control",placeholder="Gelin İsmi") }}
<small id="emailHelp" class="form-text text-muted">Gelinin ismini buraya giriniz.</small>
</div>
<hr>
<div class="form-group">
<label for="exampleFormControlFile1">Gelinin Fotoğrafı : </label>
<div class="upload">
<img src="{{ url_for('static', filename='admin/images/upload.png') }}" class="uploadImage" alt=""> {{ render_field(form.gelinFoto,id="gelinFoto",class="gdfoto",accept=".png,.jpg,.jpeg") }}
</div>
<small id="emailHelp" class="form-text text-muted">Gelinin fotoğrafını yükleyiniz.</small>
</div>
</li>
<div class="aupload">
<img src="{{ url_for('static', filename='admin/images/upload.png') }}" class="uploadImage" alt="">{{ form.files(accept=".png,.jpg,.jpeg") }} </div>
<input type="reset" onclick="remv()" class="form-control btn btn-danger remove" style="margin-bottom: 20px;" value="Temizle">
flask sqlalchemy
add a comment |
up vote
0
down vote
favorite
I'm here with a question. There's a problem. The user is registering and filling out forms after logging in to the administration panel. After filling out the forms, the save button is pressed and saved in the database. The problem starts here. That is, after pressing the Save button, it redirects to the same page. At this stage, I want the user to have the information that is saved in the database in the form and to update the database when it makes a change. I didn't understand how to do that.
Python Code :
def admin():
form = KisiForm(request.form)
if request.method == "POST":
gelinAdi = form.gelinAdi.data
gelinFoto = request.files['gelinFoto'] if request.files.get('gelinFoto') else None
gelinBio = form.gelinBio.data
gfilename = False
if gelinFoto:
yol = app.config['UPLOAD_FOLDER'] + whuser
yol = yol + '/profil'
gfilename = secure_filename(gelinFoto.filename)
gelinFoto.save(os.path.join(yol, gfilename))
if gfilename:
kisi = bilgi(gelinAdi = gelinAdi, gelinFoto = gfilename, gelinBio = gelinBio)
db.session.add(kisi)
db.session.commit()
return redirect(url_for("admin"))
return render_template("admin/index.html",form=form)
def upload():
form = albumf(request.form)
if request.method == 'POST' and 'files' in request.files:
for f in request.files.getlist('files'):
files = form.files.data
username = session["username"]
url=app.config['UPLOAD_FOLDER']+username
f.save(os.path.join(url, f.filename))
user = users.query.filter_by(username=username).first()
fotoo = foto(whfoto = user, foto=f.filename)
db.session.add(fotoo)
db.session.commit()
return render_template('/admin/galeri.html',form=form)
return render_template('/admin/galeri.html',form=form)
HTML Code (admin Panel):
<li class="col-xs-6 col-lg-6">
<div class="form-group">
<label for="exampleInputEmail1">Gelin İsmi : </label>{{ render_field(form.gelinAdi,class="form-control",placeholder="Gelin İsmi") }}
<small id="emailHelp" class="form-text text-muted">Gelinin ismini buraya giriniz.</small>
</div>
<hr>
<div class="form-group">
<label for="exampleFormControlFile1">Gelinin Fotoğrafı : </label>
<div class="upload">
<img src="{{ url_for('static', filename='admin/images/upload.png') }}" class="uploadImage" alt=""> {{ render_field(form.gelinFoto,id="gelinFoto",class="gdfoto",accept=".png,.jpg,.jpeg") }}
</div>
<small id="emailHelp" class="form-text text-muted">Gelinin fotoğrafını yükleyiniz.</small>
</div>
</li>
<div class="aupload">
<img src="{{ url_for('static', filename='admin/images/upload.png') }}" class="uploadImage" alt="">{{ form.files(accept=".png,.jpg,.jpeg") }} </div>
<input type="reset" onclick="remv()" class="form-control btn btn-danger remove" style="margin-bottom: 20px;" value="Temizle">
flask sqlalchemy
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm here with a question. There's a problem. The user is registering and filling out forms after logging in to the administration panel. After filling out the forms, the save button is pressed and saved in the database. The problem starts here. That is, after pressing the Save button, it redirects to the same page. At this stage, I want the user to have the information that is saved in the database in the form and to update the database when it makes a change. I didn't understand how to do that.
Python Code :
def admin():
form = KisiForm(request.form)
if request.method == "POST":
gelinAdi = form.gelinAdi.data
gelinFoto = request.files['gelinFoto'] if request.files.get('gelinFoto') else None
gelinBio = form.gelinBio.data
gfilename = False
if gelinFoto:
yol = app.config['UPLOAD_FOLDER'] + whuser
yol = yol + '/profil'
gfilename = secure_filename(gelinFoto.filename)
gelinFoto.save(os.path.join(yol, gfilename))
if gfilename:
kisi = bilgi(gelinAdi = gelinAdi, gelinFoto = gfilename, gelinBio = gelinBio)
db.session.add(kisi)
db.session.commit()
return redirect(url_for("admin"))
return render_template("admin/index.html",form=form)
def upload():
form = albumf(request.form)
if request.method == 'POST' and 'files' in request.files:
for f in request.files.getlist('files'):
files = form.files.data
username = session["username"]
url=app.config['UPLOAD_FOLDER']+username
f.save(os.path.join(url, f.filename))
user = users.query.filter_by(username=username).first()
fotoo = foto(whfoto = user, foto=f.filename)
db.session.add(fotoo)
db.session.commit()
return render_template('/admin/galeri.html',form=form)
return render_template('/admin/galeri.html',form=form)
HTML Code (admin Panel):
<li class="col-xs-6 col-lg-6">
<div class="form-group">
<label for="exampleInputEmail1">Gelin İsmi : </label>{{ render_field(form.gelinAdi,class="form-control",placeholder="Gelin İsmi") }}
<small id="emailHelp" class="form-text text-muted">Gelinin ismini buraya giriniz.</small>
</div>
<hr>
<div class="form-group">
<label for="exampleFormControlFile1">Gelinin Fotoğrafı : </label>
<div class="upload">
<img src="{{ url_for('static', filename='admin/images/upload.png') }}" class="uploadImage" alt=""> {{ render_field(form.gelinFoto,id="gelinFoto",class="gdfoto",accept=".png,.jpg,.jpeg") }}
</div>
<small id="emailHelp" class="form-text text-muted">Gelinin fotoğrafını yükleyiniz.</small>
</div>
</li>
<div class="aupload">
<img src="{{ url_for('static', filename='admin/images/upload.png') }}" class="uploadImage" alt="">{{ form.files(accept=".png,.jpg,.jpeg") }} </div>
<input type="reset" onclick="remv()" class="form-control btn btn-danger remove" style="margin-bottom: 20px;" value="Temizle">
flask sqlalchemy
I'm here with a question. There's a problem. The user is registering and filling out forms after logging in to the administration panel. After filling out the forms, the save button is pressed and saved in the database. The problem starts here. That is, after pressing the Save button, it redirects to the same page. At this stage, I want the user to have the information that is saved in the database in the form and to update the database when it makes a change. I didn't understand how to do that.
Python Code :
def admin():
form = KisiForm(request.form)
if request.method == "POST":
gelinAdi = form.gelinAdi.data
gelinFoto = request.files['gelinFoto'] if request.files.get('gelinFoto') else None
gelinBio = form.gelinBio.data
gfilename = False
if gelinFoto:
yol = app.config['UPLOAD_FOLDER'] + whuser
yol = yol + '/profil'
gfilename = secure_filename(gelinFoto.filename)
gelinFoto.save(os.path.join(yol, gfilename))
if gfilename:
kisi = bilgi(gelinAdi = gelinAdi, gelinFoto = gfilename, gelinBio = gelinBio)
db.session.add(kisi)
db.session.commit()
return redirect(url_for("admin"))
return render_template("admin/index.html",form=form)
def upload():
form = albumf(request.form)
if request.method == 'POST' and 'files' in request.files:
for f in request.files.getlist('files'):
files = form.files.data
username = session["username"]
url=app.config['UPLOAD_FOLDER']+username
f.save(os.path.join(url, f.filename))
user = users.query.filter_by(username=username).first()
fotoo = foto(whfoto = user, foto=f.filename)
db.session.add(fotoo)
db.session.commit()
return render_template('/admin/galeri.html',form=form)
return render_template('/admin/galeri.html',form=form)
HTML Code (admin Panel):
<li class="col-xs-6 col-lg-6">
<div class="form-group">
<label for="exampleInputEmail1">Gelin İsmi : </label>{{ render_field(form.gelinAdi,class="form-control",placeholder="Gelin İsmi") }}
<small id="emailHelp" class="form-text text-muted">Gelinin ismini buraya giriniz.</small>
</div>
<hr>
<div class="form-group">
<label for="exampleFormControlFile1">Gelinin Fotoğrafı : </label>
<div class="upload">
<img src="{{ url_for('static', filename='admin/images/upload.png') }}" class="uploadImage" alt=""> {{ render_field(form.gelinFoto,id="gelinFoto",class="gdfoto",accept=".png,.jpg,.jpeg") }}
</div>
<small id="emailHelp" class="form-text text-muted">Gelinin fotoğrafını yükleyiniz.</small>
</div>
</li>
<div class="aupload">
<img src="{{ url_for('static', filename='admin/images/upload.png') }}" class="uploadImage" alt="">{{ form.files(accept=".png,.jpg,.jpeg") }} </div>
<input type="reset" onclick="remv()" class="form-control btn btn-danger remove" style="margin-bottom: 20px;" value="Temizle">
flask sqlalchemy
flask sqlalchemy
asked Nov 19 at 13:22
Berat Bozkurt
86
86
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375570%2fshow-and-update-data-in-form-with-sqlalchemy-flask%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown