url-for

Flask: where to put static javascript files in templates

╄→尐↘猪︶ㄣ 提交于 2021-02-04 15:08:39
问题 I'm developing a flask app with the following folder structure: |-->flask_app.py |-->static |-->css |-->bootstrap.min.css |-->styles.css |-->js |-->jquery-3.1.1.min.js |-->bootstrap.min.js |-->script.js |-->templates |-->index.html What is the proper way to link to these css and js files in index.html and what parameters do I need associated with them? My CSS links look like this and are located in the header: <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">

Flask: where to put static javascript files in templates

房东的猫 提交于 2021-02-04 15:08:24
问题 I'm developing a flask app with the following folder structure: |-->flask_app.py |-->static |-->css |-->bootstrap.min.css |-->styles.css |-->js |-->jquery-3.1.1.min.js |-->bootstrap.min.js |-->script.js |-->templates |-->index.html What is the proper way to link to these css and js files in index.html and what parameters do I need associated with them? My CSS links look like this and are located in the header: <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">

Flask: where to put static javascript files in templates

余生颓废 提交于 2021-02-04 15:07:46
问题 I'm developing a flask app with the following folder structure: |-->flask_app.py |-->static |-->css |-->bootstrap.min.css |-->styles.css |-->js |-->jquery-3.1.1.min.js |-->bootstrap.min.js |-->script.js |-->templates |-->index.html What is the proper way to link to these css and js files in index.html and what parameters do I need associated with them? My CSS links look like this and are located in the header: <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">

Flaskr url_for with parameters not working when called from javascript to python

人盡茶涼 提交于 2021-01-04 15:57:35
问题 I am in the middle of creation of a web application. In javascript, I make a ajax call to my python script, process and send the result back as response. /process/ is the route to the python script for the processing of values which are sent as json, namely value1 and value2. I send back response as json setting value in key 'result'. In the success block of ajax, the value is stored in name_value and this should be passed as parameter to the python routing method. Javascript: $.ajax({ type:

Flaskr url_for with parameters not working when called from javascript to python

时光总嘲笑我的痴心妄想 提交于 2021-01-04 15:55:11
问题 I am in the middle of creation of a web application. In javascript, I make a ajax call to my python script, process and send the result back as response. /process/ is the route to the python script for the processing of values which are sent as json, namely value1 and value2. I send back response as json setting value in key 'result'. In the success block of ajax, the value is stored in name_value and this should be passed as parameter to the python routing method. Javascript: $.ajax({ type:

Is it safe to accept URL parameters for populating the `url_for` method?

偶尔善良 提交于 2020-01-04 03:25:11
问题 I am using Ruby on Rails 4.1.1 and I am thinking to accept parameters (through URL query strings) that are passed directly to the url_for method, this way: # URL in the browser http://www.myapp.com?redirect_to[controller]=users&redirect_to[action]=show&redirect_to[id]=1 # Controller ... redirect_to url_for(params[:redirect_to].merge(:only_path => true)) Adopting the above approach users can be redirected after performing an action. However, I think people can enter arbitrary params that can

how to use Flask Jinja2 url_for with multiple parameters

ぃ、小莉子 提交于 2019-12-31 22:23:27
问题 I have a problem while using jinja2 url_for() function. I have a route like this: @app.route('/article/<int:article_id>/<url_title>/', methods=['GET']) def article_page(article_id, url_title): article = Article.query.get(article_id) if article == None: abort(404) return render_template('article.html', article=article) in jinja template file,i want to create a url which links to article_page,so i write like this: <h5> <a href="{{ url_for('article_page',article_id=article.id,url_title=article

how to use Flask Jinja2 url_for with multiple parameters

故事扮演 提交于 2019-12-31 22:23:15
问题 I have a problem while using jinja2 url_for() function. I have a route like this: @app.route('/article/<int:article_id>/<url_title>/', methods=['GET']) def article_page(article_id, url_title): article = Article.query.get(article_id) if article == None: abort(404) return render_template('article.html', article=article) in jinja template file,i want to create a url which links to article_page,so i write like this: <h5> <a href="{{ url_for('article_page',article_id=article.id,url_title=article

How to generate custom sorted query string URL in Rails link_to?

♀尐吖头ヾ 提交于 2019-12-24 08:25:42
问题 When I use link_to helper in Rails 3.0.7 app with many parameters, it generates a lexicographically sorted url as probably mentioned in the to_param method for Hash in Activesupport documentation. e.g. link_to "my Link", {:u=>"user", :q=>"some query", :page=>"4"} generates "/search?page=4&q=some+query&u=user" but what i want is "/search?u=user&q=some+query&page=4" Anyone able to do custom sorting as supplied in the params hash to link_to or url_for ? Unless I am missing something, this seems

Query parameters with url_for?

拥有回忆 提交于 2019-12-18 18:36:28
问题 url_for([:edit, @post]) is working and generating /comments/123/edit . Now I need to add a query parameter, so that instead of /comments/123/edit it is /comments/123/edit?qp=asdf I tried url_for([:edit, @post], :qp => "asdf") but no go. 回答1: Use named routes. edit_post_path(@post, :qp => "asdf") 回答2: You can use polymorphic_path polymorphic_path([:edit, @post], :qp => 'asdf') 回答3: You can pass params to url_for . Checkout it in the sourcecode: https://github.com/rails/rails/blob