Create an edit form with previously populated fields, facing difficulties with input[file] and textareaHow do you disable browser Autocomplete on web form field / input tag?How to focus on a form input text field on page load using jQuery?What's the difference between disabled=“disabled” and readonly=“readonly” for HTML form input fields?Flask-WTF form populating integer fields and radio fieldsreset form fields previously populated with $_POST variablesCannot display HTML stringPre-Populate an edit form with WTForms and Flaskflask peewee how to change the field order when edit/creating formsPopulate div input form field value with variable dataHow do I retrieve values from a “User” and pre-populate the form when it comes to html: input[password] and textarea?

Nested-Loop-Join: How many comparisons and how many pages-accesses?

Align by center of symbol

Why hasn't the U.S. government paid war reparations to any country it attacked?

Too many spies!

Can a continent naturally split into two distant parts within a week?

What exactly is the Tension force?

Deep Learning based time series forecasting

Published paper containing well-known results

Why are Japanese translated subtitles non-conversational?

Why does the trade federation become so alarmed upon learning the ambassadors are Jedi Knights?

Nikon FM2 lever cannot advance

Access files in Home directory from live mode

Book or series about stones and a magician named Gwydion

Alternatives to using writing paper for writing practice

Does optical correction here give more aesthetic look to logo?

Possible isometry groups of open manifolds

Why is dry soil hydrophobic? Bad gardener paradox

Cubic programming and beyond?

Meaning of slash chord without anything left of the slash

Why do they not say "The Baby"

How do I define this subset using mathematical notation?

Crab Nebula short story from 1960s or '70s

Does Google Maps take into account hills/inclines for route times?

Absconding a company after 1st day of joining



Create an edit form with previously populated fields, facing difficulties with input[file] and textarea


How do you disable browser Autocomplete on web form field / input tag?How to focus on a form input text field on page load using jQuery?What's the difference between disabled=“disabled” and readonly=“readonly” for HTML form input fields?Flask-WTF form populating integer fields and radio fieldsreset form fields previously populated with $_POST variablesCannot display HTML stringPre-Populate an edit form with WTForms and Flaskflask peewee how to change the field order when edit/creating formsPopulate div input form field value with variable dataHow do I retrieve values from a “User” and pre-populate the form when it comes to html: input[password] and textarea?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am doing a Python Flask project, trying to "edit" a current "object" from postgresql via FlaskForm. So far, I have managed to retrieve the values of the "recipe" object using value for but I need to manually render recipe.description.



However, how do I go about the same using the input[file] to retrieve recipe.picture ?



(https://imgur.com/6zfLjBE)
enter image description here



Here is my form.html



<form method="POST" action=" url_for('recipes.edit_recipe', recipe_id=recipe.id) " enctype="multipart/form-data">
form.csrf_token
form.hidden_tag()
<fieldset class="form-group">
<div class="modal-body">
% for field in form if field.name != "csrf_token" %
% if field.name != "btn" %
<div class="form-group">
field.label(class="form-control-label form-control-lg")
<!-- if fiend.something == title, need to insert title -->
% if field.name == "picture" %
field(class="form-control", value=recipe.picture)
<figure>
<img src="recipe.picture" class="small-preview" alt="preview">
<figcaption>Current photo</figcaption>
</figure>
% endif %
% if field.name == "title" %
field(class="form-control", value=recipe.title)
% endif %
% if field.name == "description" %
<textarea class="form-control" name="description" id="description" cols="30" rows="5"> recipe.description </textarea>
% endif %
<!-- end the if block -->
% for error in field.errors %
error
% endfor %
</div>
% else %
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
form.btn(class="btn btn-info")
</div>
% endif %
% endfor %
</div>
</fieldset>
</form>


Here is my views.py



@recipes_blueprint.route('/<int:recipe_id>', methods=['POST'])
@login_required
def edit_recipe(recipe_id):
form = UpdateRecipeForm()
that_recipe = Recipe.get_or_none(Recipe.id == recipe_id)
recipe_owner = User.get_or_none(User.id == that_recipe.user_id)
if form.validate_on_submit():
if recipe_owner != current_user:
flash("Only owner of the recipe can amend the details", "danger")
return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
else:
if "picture" not in request.files:
flash("No picture key in request.files", 'danger')
return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
file = request.files['picture']
if file.filename == '':
flash("Please select a file", 'danger')
return redirect(url_for('users.update_user'))
if file and allowed_file(file.filename):
file.filename = secure_filename(file.filename)
output = upload_file_to_s3(file, app.config['S3_BUCKET'])
updated_recipe = Recipe.update(
title=form.data['title'],
description=form.data['description'],
picture=output
).where(Recipe.user_id == recipe_owner.id)
updated_recipe.execute()
flash("Recipe updated successfully", "success")
return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
return render_template('read_that_recipe.html', recipe=that_recipe, form=form)









share|improve this question




























    0















    I am doing a Python Flask project, trying to "edit" a current "object" from postgresql via FlaskForm. So far, I have managed to retrieve the values of the "recipe" object using value for but I need to manually render recipe.description.



    However, how do I go about the same using the input[file] to retrieve recipe.picture ?



    (https://imgur.com/6zfLjBE)
    enter image description here



    Here is my form.html



    <form method="POST" action=" url_for('recipes.edit_recipe', recipe_id=recipe.id) " enctype="multipart/form-data">
    form.csrf_token
    form.hidden_tag()
    <fieldset class="form-group">
    <div class="modal-body">
    % for field in form if field.name != "csrf_token" %
    % if field.name != "btn" %
    <div class="form-group">
    field.label(class="form-control-label form-control-lg")
    <!-- if fiend.something == title, need to insert title -->
    % if field.name == "picture" %
    field(class="form-control", value=recipe.picture)
    <figure>
    <img src="recipe.picture" class="small-preview" alt="preview">
    <figcaption>Current photo</figcaption>
    </figure>
    % endif %
    % if field.name == "title" %
    field(class="form-control", value=recipe.title)
    % endif %
    % if field.name == "description" %
    <textarea class="form-control" name="description" id="description" cols="30" rows="5"> recipe.description </textarea>
    % endif %
    <!-- end the if block -->
    % for error in field.errors %
    error
    % endfor %
    </div>
    % else %
    <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
    form.btn(class="btn btn-info")
    </div>
    % endif %
    % endfor %
    </div>
    </fieldset>
    </form>


    Here is my views.py



    @recipes_blueprint.route('/<int:recipe_id>', methods=['POST'])
    @login_required
    def edit_recipe(recipe_id):
    form = UpdateRecipeForm()
    that_recipe = Recipe.get_or_none(Recipe.id == recipe_id)
    recipe_owner = User.get_or_none(User.id == that_recipe.user_id)
    if form.validate_on_submit():
    if recipe_owner != current_user:
    flash("Only owner of the recipe can amend the details", "danger")
    return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
    else:
    if "picture" not in request.files:
    flash("No picture key in request.files", 'danger')
    return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
    file = request.files['picture']
    if file.filename == '':
    flash("Please select a file", 'danger')
    return redirect(url_for('users.update_user'))
    if file and allowed_file(file.filename):
    file.filename = secure_filename(file.filename)
    output = upload_file_to_s3(file, app.config['S3_BUCKET'])
    updated_recipe = Recipe.update(
    title=form.data['title'],
    description=form.data['description'],
    picture=output
    ).where(Recipe.user_id == recipe_owner.id)
    updated_recipe.execute()
    flash("Recipe updated successfully", "success")
    return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
    return render_template('read_that_recipe.html', recipe=that_recipe, form=form)









    share|improve this question
























      0












      0








      0








      I am doing a Python Flask project, trying to "edit" a current "object" from postgresql via FlaskForm. So far, I have managed to retrieve the values of the "recipe" object using value for but I need to manually render recipe.description.



      However, how do I go about the same using the input[file] to retrieve recipe.picture ?



      (https://imgur.com/6zfLjBE)
      enter image description here



      Here is my form.html



      <form method="POST" action=" url_for('recipes.edit_recipe', recipe_id=recipe.id) " enctype="multipart/form-data">
      form.csrf_token
      form.hidden_tag()
      <fieldset class="form-group">
      <div class="modal-body">
      % for field in form if field.name != "csrf_token" %
      % if field.name != "btn" %
      <div class="form-group">
      field.label(class="form-control-label form-control-lg")
      <!-- if fiend.something == title, need to insert title -->
      % if field.name == "picture" %
      field(class="form-control", value=recipe.picture)
      <figure>
      <img src="recipe.picture" class="small-preview" alt="preview">
      <figcaption>Current photo</figcaption>
      </figure>
      % endif %
      % if field.name == "title" %
      field(class="form-control", value=recipe.title)
      % endif %
      % if field.name == "description" %
      <textarea class="form-control" name="description" id="description" cols="30" rows="5"> recipe.description </textarea>
      % endif %
      <!-- end the if block -->
      % for error in field.errors %
      error
      % endfor %
      </div>
      % else %
      <div class="modal-footer">
      <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      form.btn(class="btn btn-info")
      </div>
      % endif %
      % endfor %
      </div>
      </fieldset>
      </form>


      Here is my views.py



      @recipes_blueprint.route('/<int:recipe_id>', methods=['POST'])
      @login_required
      def edit_recipe(recipe_id):
      form = UpdateRecipeForm()
      that_recipe = Recipe.get_or_none(Recipe.id == recipe_id)
      recipe_owner = User.get_or_none(User.id == that_recipe.user_id)
      if form.validate_on_submit():
      if recipe_owner != current_user:
      flash("Only owner of the recipe can amend the details", "danger")
      return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
      else:
      if "picture" not in request.files:
      flash("No picture key in request.files", 'danger')
      return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
      file = request.files['picture']
      if file.filename == '':
      flash("Please select a file", 'danger')
      return redirect(url_for('users.update_user'))
      if file and allowed_file(file.filename):
      file.filename = secure_filename(file.filename)
      output = upload_file_to_s3(file, app.config['S3_BUCKET'])
      updated_recipe = Recipe.update(
      title=form.data['title'],
      description=form.data['description'],
      picture=output
      ).where(Recipe.user_id == recipe_owner.id)
      updated_recipe.execute()
      flash("Recipe updated successfully", "success")
      return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
      return render_template('read_that_recipe.html', recipe=that_recipe, form=form)









      share|improve this question














      I am doing a Python Flask project, trying to "edit" a current "object" from postgresql via FlaskForm. So far, I have managed to retrieve the values of the "recipe" object using value for but I need to manually render recipe.description.



      However, how do I go about the same using the input[file] to retrieve recipe.picture ?



      (https://imgur.com/6zfLjBE)
      enter image description here



      Here is my form.html



      <form method="POST" action=" url_for('recipes.edit_recipe', recipe_id=recipe.id) " enctype="multipart/form-data">
      form.csrf_token
      form.hidden_tag()
      <fieldset class="form-group">
      <div class="modal-body">
      % for field in form if field.name != "csrf_token" %
      % if field.name != "btn" %
      <div class="form-group">
      field.label(class="form-control-label form-control-lg")
      <!-- if fiend.something == title, need to insert title -->
      % if field.name == "picture" %
      field(class="form-control", value=recipe.picture)
      <figure>
      <img src="recipe.picture" class="small-preview" alt="preview">
      <figcaption>Current photo</figcaption>
      </figure>
      % endif %
      % if field.name == "title" %
      field(class="form-control", value=recipe.title)
      % endif %
      % if field.name == "description" %
      <textarea class="form-control" name="description" id="description" cols="30" rows="5"> recipe.description </textarea>
      % endif %
      <!-- end the if block -->
      % for error in field.errors %
      error
      % endfor %
      </div>
      % else %
      <div class="modal-footer">
      <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      form.btn(class="btn btn-info")
      </div>
      % endif %
      % endfor %
      </div>
      </fieldset>
      </form>


      Here is my views.py



      @recipes_blueprint.route('/<int:recipe_id>', methods=['POST'])
      @login_required
      def edit_recipe(recipe_id):
      form = UpdateRecipeForm()
      that_recipe = Recipe.get_or_none(Recipe.id == recipe_id)
      recipe_owner = User.get_or_none(User.id == that_recipe.user_id)
      if form.validate_on_submit():
      if recipe_owner != current_user:
      flash("Only owner of the recipe can amend the details", "danger")
      return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
      else:
      if "picture" not in request.files:
      flash("No picture key in request.files", 'danger')
      return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
      file = request.files['picture']
      if file.filename == '':
      flash("Please select a file", 'danger')
      return redirect(url_for('users.update_user'))
      if file and allowed_file(file.filename):
      file.filename = secure_filename(file.filename)
      output = upload_file_to_s3(file, app.config['S3_BUCKET'])
      updated_recipe = Recipe.update(
      title=form.data['title'],
      description=form.data['description'],
      picture=output
      ).where(Recipe.user_id == recipe_owner.id)
      updated_recipe.execute()
      flash("Recipe updated successfully", "success")
      return redirect(url_for('recipes.read_recipe', recipe_id=recipe_id))
      return render_template('read_that_recipe.html', recipe=that_recipe, form=form)






      html python-3.x flask jinja2 peewee






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 26 at 6:28









      Chai Chong TehChai Chong Teh

      385 bronze badges




      385 bronze badges






















          0






          active

          oldest

          votes










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55351009%2fcreate-an-edit-form-with-previously-populated-fields-facing-difficulties-with-i%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55351009%2fcreate-an-edit-form-with-previously-populated-fields-facing-difficulties-with-i%23new-answer', 'question_page');

          );

          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







          Popular posts from this blog

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해