Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

Flask Post method unexpected keyword argument

$
0
0

I want to perform two actions on one route:

  1. I want to show only information from table jobs for a specificID that was provided on the previous page.

  2. After clicking the Apply button I want to insert a new record to thetable dashboard.

Terminal shows me that:dashboard_add() got an unexpected argument 'job_id'

Python code:

@app.route('/jobs/<job_id>') def job_detailed_view(job_id):     detailed_view = fetch_specific(job_id)     return render_template('detailed-view.html', job=detailed_view)def fetch_specific(job_id):     query = """             SELECT * FROM jobs             WHERE job_id = %(job_id)s"""     return execute_select(query, {'job_id': job_id}, False)@app.route('/jobs/<job_id>', methods=['POST'])def dashboard_add():     apply_date = datetime.now()     apply_date.strftime("%d/%m/%y")     applied_job_id = int(request.form.get('add_item_index', 0))     apply_job(applied_job_id, apply_date)     return redirect('home')def apply_job(job_id, apply_date):     execute_insert ("""             INSERT INTO dashboard (job_id, apply_date)              VALUES             (%(job_id)s, %(apply_date)s)""", {'job_id': job_id, 'apply_date': apply_date})

Also HTML looks like this:

First code re-directs to the page with specific id and the second should pass the data to POST method.

<div class="job-title"><a href="{{ "/jobs/" + (job['job_id']|string) }}">{{job['job_title']}}</a></div><form method="post" action="{{ "/jobs/" + (job['job_id']|string)}}"><input type="hidden" name="add_item_index" value="3"><button class="apply" type="submit" name="add_item">  Apply</button></form>

Any ideas what I'm doing wrong?

I created one route with two different functions to avoid performing two actions in one route.


Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>