Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

405 Method Not Allowed When Redirecting in Flask within POST route

@app.route('/submit_review/<game_id>', methods=['POST'])
def submit_review(game_id):
    """
    Adds users review to database.
    """

    existing_game = Game.query.filter_by(igdb_id=game_id).first()

    if not existing_game:
        igdb_game_data = get_game_data_by_id(game_id)[0]
        igdb_game_artwork = get_game_artwork(game_id)
        igdb_game_cover = get_game_cover_art(game_id)

        game = Game(
            name=igdb_game_data['name'],
            artwork=json.dumps(igdb_game_artwork),
            summary=igdb_game_data['summary'],
            igdb_id=igdb_game_data['id'],
            cover_art=igdb_game_cover
        )

        db.session.add(game)
        db.session.commit()

    user = User.query.filter_by(username=session['username']).first()
    game = Game.query.filter_by(igdb_id=game_id).first()

    existing_review = Review.query.filter_by(user_id=user.id,
                                             game_id=game.id).first()

    review = Review(
        user_id=user.id,
        game_id=game.id,
        rating=float(request.form.get('review-rating')),
        heading=request.form.get('review-heading'),
        liked_text=request.form.get('liked-text'),
        disliked_text=request.form.get('disliked-text'),
        hours=int(request.form.get('review-hours')),
    )

    if existing_review:
        print(request)
        flash('You have already created a review for this game')
        return redirect(url_for('manage'))

    db.session.add(review)
    db.session.commit()

    flash('Review added successfully')
    return redirect(url_for('home'))
Comment

405 Method Not Allowed When Redirecting in Flask within POST route

@app.route('/submit_review/<game_id>', methods=['POST'])
def submit_review(game_id):
    """
    Adds users review to database.
    """

    existing_game = Game.query.filter_by(igdb_id=game_id).first()

    if not existing_game:
        igdb_game_data = get_game_data_by_id(game_id)[0]
        igdb_game_artwork = get_game_artwork(game_id)
        igdb_game_cover = get_game_cover_art(game_id)

        game = Game(
            name=igdb_game_data['name'],
            artwork=json.dumps(igdb_game_artwork),
            summary=igdb_game_data['summary'],
            igdb_id=igdb_game_data['id'],
            cover_art=igdb_game_cover
        )

        db.session.add(game)
        db.session.commit()

    user = User.query.filter_by(username=session['username']).first()
    game = Game.query.filter_by(igdb_id=game_id).first()

    existing_review = Review.query.filter_by(user_id=user.id,
                                             game_id=game.id).first()

    if existing_review:
        print(request)
        flash('You have already created a review for this game')
        return redirect(url_for('manage'))

    review = Review(
        user_id=user.id,
        game_id=game.id,
        rating=float(request.form.get('review-rating')),
        heading=request.form.get('review-heading'),
        liked_text=request.form.get('liked-text'),
        disliked_text=request.form.get('disliked-text'),
        hours=int(request.form.get('review-hours')),
    )

    db.session.add(review)
    db.session.commit()

    flash('Review added successfully')
    return redirect(url_for('home'))
Comment

PREVIOUS NEXT
Code Example
Python :: HTML default value fo radio button input type based on python variable 
Python :: HTML not being displayed properly in Flask, Python 
Python :: Dynamic use of templates in Jinja2 
Python :: Deploying matlab app on the web using python 
Python :: if space bar pressed pygame 
Python :: python class reflect method of member instance 
Python :: typing effect python 
Python :: how to import grades into a text file in python 
Python :: for y in range(10): for x in range(y): print("*",end=') print() 
Python :: xchacha20 
Python :: element tree no able to find tag 
Python :: ring load the odbclib.ring library 
Python :: qtextedit insert unicode 
Python :: pandas rolling list 
Python :: python list insert multiple 
Python :: salamelecus 
Python :: Use of OfficeApi 
Python :: instaed of: output = "Programming" + "is" + "fun -- use join 
Python :: obtenir coordonnees souris python 
Python :: dbscan multidimensional data 
Python :: python class overwrite length method 
Python :: how to insert value in admin panel in django 
Python :: python post np.array object 
Python :: 1007 solution python 
Python :: how to incorportate a different language in python code 
Python :: python copy virtual env modules 
Python :: sending whatsapp message from python notebook 
Python :: reshaping a image vector/matrix 
Python :: stack overflow pop item from list in python 
Python :: gricsearchcv sample_weights 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =