url-for

Build error with variables and url_for in Flask

痴心易碎 提交于 2019-12-18 04:35:20
问题 Have found one or two people on the interwebs with similar problems, but haven't seen a solution posted anywhere. I'm getting a build error from the code/template below, but can't figure out where the issue is or why it's occurring. It appears that the template isn't recognizing the function, but don't know why this would be occurring. Any help would be greatly appreciated - have been pounding my against the keyboard for two nights now. Function: @app.route('/viewproj/<proj>', methods=['GET',

Creating link to an url of Flask app in jinja2 template

泪湿孤枕 提交于 2019-12-17 21:48:20
问题 In my Flask app, I have a view which displays a post @post_blueprint.route('/post/<int:year>/<int:month>/<title>') def get_post(year,month,title): # My code To display the last 10 entries, I have following view: @post_blueprint.route('/posts/') def get_all_posts(): # My code return render_template('p.html',posts=posts) Now when I display the last 10 posts, I want to convert the title of a post into a hyperlink. Currently I have to do the following in my jinja template to achieve this: <a href

how to use redirect(url_for('index')) with id to reload the index.html with specific section

爷,独闯天下 提交于 2019-12-13 21:21:22
问题 My index.html file contains Links to a location/sections on the same page; one of which is 'content'. After sending email when I am using below line in my .py - return redirect(url_for('index')) I wanted to reopen my index.html with section which id=content I tried - url_for('index',id="content") but not working. Which way should I modify my redirect(url_for.... line to achieve this? Please help. 回答1: You can pass your id as _anchor : url_for('index', _anchor="content") See url_for's docs for

Rails 5.1 API - incorrect url_for with a nested resource

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 03:04:20
问题 Given this route structure: routes: namespace :api do resources :templates do resources :template_items end end I scaffolded the template_items controller (but cannot recall exactly what I specified) but it gave me this create action: # POST /template_items def create @template_item = TemplateItem.new(template_item_params) if @template_item.save render json: @template_item, status: :created, location: @template_item else render json: @template_item.errors, status: :unprocessable_entity end

Call to expire_fragment raises “ to use #url_for, you must include routing helpers explicitly” error

笑着哭i 提交于 2019-12-12 15:39:21
问题 I've been upgrading a Rails 2 app to Rails 3.2.13 and am having a problems when I try to enable caching. Caching worked in Rails 2 and I'm using the same version of Ruby - 1.8.7. I'm not sure if it is relevant but I'm developing on OSX. The error's being thrown from the ActionController::Caching::Fragments class when expire_fragment is called. expire_fragment makes a call to fragment_cache_key which contains this: ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://

url_for: how to look into another folder other than static

半世苍凉 提交于 2019-12-12 13:49:37
问题 I have a file test.css in a folder called css. I want to create url for this file. I know that I can use url_for like url_for('static', filename="test.css") to create url like static/test.css but I am not able to use like url_for('css', filename="test.css") to create the url that I am interested in css/test.css How can I do this? 回答1: static just endpoint, see route and view. So you can create own endpoints: app.add_url_rule('/css/<path:filename>', endpoint='css', view_func=app.send_static

Cannot Generate a POST Request on Flask using url_for [duplicate]

旧巷老猫 提交于 2019-12-12 06:13:36
问题 This question already has answers here : POST from an <A> tag (10 answers) Closed 4 years ago . I am attempting to create a button that allows for a user to delete a user on the my system by passing through a post request to the following view. My challenge is that I cannot get submission portion of the form to trigger a POST request, it always generates GET and then fails to delete the user : <a href="{{ url_for('users.user_delete_admin', id=user.id) }}" class="btn btn-danger btn-xs" >Delete

Routes stopped working when upgrading Rails 3.0 to 3.1

↘锁芯ラ 提交于 2019-12-12 02:06:42
问题 I am using Ruby 1.8.7 with Rails 3.1. My application worked fine in Rails 3.0 but when I bumped it up to Rails 3.1.4, all my url helpers broke! After Googling like a mad man the past 2 days, I have given up and the time has come to seek help. I don't believe the problem is with my routes.rb file but something more on the view/helper side. I have the following in my routes.rb: resources :sessions In my homepage view I have the following link_to, which errors out: <%= link_to "Login", new

Flask function url_for doesn't work for sub-domain deployment on Bluehost

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 02:25:34
问题 I deployed a very simple Flask application called 'app' in a sub directory under root directory in Bluehost. Hopefully, example.com points to the homepage and example.com/app points to my Flask application. Actually, the Flask application works pretty fine when the script index.py looks like: from flask import Flask app = Flask(__name__) @app.route('/', methods=['GET']) def home(): return 'Hello world' if __name__ == "__main__": app.run() But things went bad as I introduced a simple login

Jinja variables within the Flask url_for function [duplicate]

点点圈 提交于 2019-12-04 18:24:56
问题 This question already has an answer here : Reference template variable within Jinja expression (1 answer) Closed 3 years ago . I have tried multiple different things, but cannot get the URL to appear as /item like I want it to. I know that everything else is functioning correctly because if I simply replace {{item}} with a string, it works fine. Am I missing something here? Here is the code section where the problem lies: <div class="person_images_group"> {% for item in names %} <div class=