[AF] Flask hyperlinks with ajax
Hi everyone, I'm making an application with flask, and I'd like to have a link on my page that send some data to the server, does some stuff with it, and then returns one or multiple hyperlinks to be displayed on the page as a result. I want to do this on the existing page, not load a different page. I figured out how to do this with Jquery/Ajax, but I'm running into errors when rendering a url pointing to an internal location. Below is an example, as simplified as I can make it.
Flask app:
from flask import Flask, url_for, render_template
app = Flask(__name__)
@app.route('/start', methods = ['GET','POST'])
def start():
return render_template('index_test.html')
@app.route('/next_page', methods = ['POST', 'GET'])
def next_page():
return render_template('next_page.html')
@app.route('/get_url', methods = ['POST', 'GET'])
def get_url():
return '<a href="{{ url_for(\'next_page\' )}}"> ajax link </a> '
if __name__ == '__main__':
app.run(debug = True)
Start page:
<html>
<head>
<script type = "text/javascript" src="{{ url_for('static', filename='jquery-2.1.1.min.js') }}"></script>
<head>
<body>
<div>
<a href="{{ url_for('next_page')}}">go to next page</a>
<a id = "link1" href="javascript:void(0)">now with ajax</a>
</div>
<div id="new_link">
</div>
<script type="text/javascript">
$("#link1").click(function(){
$.post('/get_url', function(result){
console.log(result);
$("#new_link").html(result);
});
});
</script>
</body>
So the idea is the ajax link, when clicked, will send data to the server (data not shown here, I stripped all extraneous info I could), then the server will return one or more unique hyperlinks. That is all working. The problem is that the hyperlink that the ajax request creates, inside of the #new_link div, does not look like localhost:5000/next_page as I expect. Instead it looks like localhost:5000/{{ url_for('next_page') }} . It isn't being converted to the correct hyperlink, though I think I'm using the right format. I've looked for any possible errors I could be making by mistyping the url, but I can't find any. I suspect my error has something to do with sending the new urls in via ajax, but I'm kind of stuck in my troubleshooting. Can anyone help out?
Thanks.
/r/flask
https://redd.it/5xax19
Hi everyone, I'm making an application with flask, and I'd like to have a link on my page that send some data to the server, does some stuff with it, and then returns one or multiple hyperlinks to be displayed on the page as a result. I want to do this on the existing page, not load a different page. I figured out how to do this with Jquery/Ajax, but I'm running into errors when rendering a url pointing to an internal location. Below is an example, as simplified as I can make it.
Flask app:
from flask import Flask, url_for, render_template
app = Flask(__name__)
@app.route('/start', methods = ['GET','POST'])
def start():
return render_template('index_test.html')
@app.route('/next_page', methods = ['POST', 'GET'])
def next_page():
return render_template('next_page.html')
@app.route('/get_url', methods = ['POST', 'GET'])
def get_url():
return '<a href="{{ url_for(\'next_page\' )}}"> ajax link </a> '
if __name__ == '__main__':
app.run(debug = True)
Start page:
<html>
<head>
<script type = "text/javascript" src="{{ url_for('static', filename='jquery-2.1.1.min.js') }}"></script>
<head>
<body>
<div>
<a href="{{ url_for('next_page')}}">go to next page</a>
<a id = "link1" href="javascript:void(0)">now with ajax</a>
</div>
<div id="new_link">
</div>
<script type="text/javascript">
$("#link1").click(function(){
$.post('/get_url', function(result){
console.log(result);
$("#new_link").html(result);
});
});
</script>
</body>
So the idea is the ajax link, when clicked, will send data to the server (data not shown here, I stripped all extraneous info I could), then the server will return one or more unique hyperlinks. That is all working. The problem is that the hyperlink that the ajax request creates, inside of the #new_link div, does not look like localhost:5000/next_page as I expect. Instead it looks like localhost:5000/{{ url_for('next_page') }} . It isn't being converted to the correct hyperlink, though I think I'm using the right format. I've looked for any possible errors I could be making by mistyping the url, but I can't find any. I suspect my error has something to do with sending the new urls in via ajax, but I'm kind of stuck in my troubleshooting. Can anyone help out?
Thanks.
/r/flask
https://redd.it/5xax19
reddit
[AF] Flask hyperlinks with ajax • r/flask
Hi everyone, I'm making an application with flask, and I'd like to have a link on my page that send some data to the server, does some stuff with...
Matplotlib 2.1.0 released with major new features
http://matplotlib.org/users/whats_new.html#new-in-matplotlib-2-1
/r/Python
https://redd.it/7501ch
http://matplotlib.org/users/whats_new.html#new-in-matplotlib-2-1
/r/Python
https://redd.it/7501ch
What’s new in Matplotlib — Matplotlib 2.1.0
http://matplotlib.org/users/whats_new.html#new-in-matplotlib-2-1
/r/IPython
https://redd.it/751fi9
http://matplotlib.org/users/whats_new.html#new-in-matplotlib-2-1
/r/IPython
https://redd.it/751fi9
reddit
What’s new in Matplotlib — Matplotlib 2.1.0 • r/IPython
14 points and 0 comments so far on reddit
Gamestonk Terminal: 100% python based terminal
Hey all,
Monthly update on the state of the best -and only one- Free Open-Source Terminal: [Gamestonk Terminal](https://gamestonkterminal.netlify.app/). Repository: [https://github.com/GamestonkTerminal/GamestonkTerminal](https://github.com/GamestonkTerminal/GamestonkTerminal).
**Since last month, some of the features that have been added are:**
* **Insider Screener** based on [http://openinsider.com](http://openinsider.com/)
https://preview.redd.it/tq4ttm824ed71.png?width=2212&format=png&auto=webp&s=c4cb13b19409a946462fa2c022f8ad3d793a32a3
* **Market overview** from [https://www.wsj.com/market-data](https://www.wsj.com/market-data)
* A neat **ETF screener** to filter for ETFs that meet a certain criteria, like: price, assets held, net asset valuation, expense ratio, PE Ratio, dividend yield, and more.
* An initial version of a **supply-chain analysis**, that based on a company shows not only the suppliers but also customers.
* Literally **40 new crypto commands** from a single contributor (author of [https://www.reddit.com/r/Python/comments/nwj221/moonbag\_explore\_crypto\_data\_with\_simple\_python\_cli/](https://www.reddit.com/r/Python/comments/nwj221/moonbag_explore_crypto_data_with_simple_python_cli/))! It's actually insane the amount of new functionalities this crypto menu already has...
* We incorporated also an **Options screener** from [https://ops.syncretism.io](https://ops.syncretism.io/). The author ([https://www.reddit.com/r/thetagang/comments/o6yx3e/i\_made\_an\_open\_source\_options\_search\_engine/](https://www.reddit.com/r/thetagang/comments/o6yx3e/i_made_an_open_source_options_search_engine/)) has been extremely keen with incorporating his API.
* For more terminal updates, you can follow our twitter account [https://twitter.com/gamestonkt](https://twitter.com/gamestonkt) or check the #new-features channel on [our discord](https://discord.gg/Up2QGbMKHY).
**Some of the next steps:**
* Review and merge this [Pull Request #562](https://github.com/GamestonkTerminal/GamestonkTerminal/pull/562). The reason why we are excited about this one, is that this one contains data from [Sentiment Investor](https://sentimentinvestor.com/screener)!!! Yes, you read it right! This adds another data provider to our list of partnerships: [QuiverQuant](https://www.quiverquant.com/) and [FinBrain](https://finbrain.tech/).
* We want to
/r/Python
https://redd.it/orfbxj
Hey all,
Monthly update on the state of the best -and only one- Free Open-Source Terminal: [Gamestonk Terminal](https://gamestonkterminal.netlify.app/). Repository: [https://github.com/GamestonkTerminal/GamestonkTerminal](https://github.com/GamestonkTerminal/GamestonkTerminal).
**Since last month, some of the features that have been added are:**
* **Insider Screener** based on [http://openinsider.com](http://openinsider.com/)
https://preview.redd.it/tq4ttm824ed71.png?width=2212&format=png&auto=webp&s=c4cb13b19409a946462fa2c022f8ad3d793a32a3
* **Market overview** from [https://www.wsj.com/market-data](https://www.wsj.com/market-data)
* A neat **ETF screener** to filter for ETFs that meet a certain criteria, like: price, assets held, net asset valuation, expense ratio, PE Ratio, dividend yield, and more.
* An initial version of a **supply-chain analysis**, that based on a company shows not only the suppliers but also customers.
* Literally **40 new crypto commands** from a single contributor (author of [https://www.reddit.com/r/Python/comments/nwj221/moonbag\_explore\_crypto\_data\_with\_simple\_python\_cli/](https://www.reddit.com/r/Python/comments/nwj221/moonbag_explore_crypto_data_with_simple_python_cli/))! It's actually insane the amount of new functionalities this crypto menu already has...
* We incorporated also an **Options screener** from [https://ops.syncretism.io](https://ops.syncretism.io/). The author ([https://www.reddit.com/r/thetagang/comments/o6yx3e/i\_made\_an\_open\_source\_options\_search\_engine/](https://www.reddit.com/r/thetagang/comments/o6yx3e/i_made_an_open_source_options_search_engine/)) has been extremely keen with incorporating his API.
* For more terminal updates, you can follow our twitter account [https://twitter.com/gamestonkt](https://twitter.com/gamestonkt) or check the #new-features channel on [our discord](https://discord.gg/Up2QGbMKHY).
**Some of the next steps:**
* Review and merge this [Pull Request #562](https://github.com/GamestonkTerminal/GamestonkTerminal/pull/562). The reason why we are excited about this one, is that this one contains data from [Sentiment Investor](https://sentimentinvestor.com/screener)!!! Yes, you read it right! This adds another data provider to our list of partnerships: [QuiverQuant](https://www.quiverquant.com/) and [FinBrain](https://finbrain.tech/).
* We want to
/r/Python
https://redd.it/orfbxj
gamestonkterminal.netlify.app
Gamestonk Terminal
Gamestonk Terminal is a DIY, Meme Stock Version of Bloomberg Terminal
How to write a simple password changer?
Hi,
can you please explain how to create a password changer? After providing first password to the user, user should be able to change their fist password with their preference. So I created the code below. Could you please provide the necessary part?
@app.route("/changepassword",methods=['GET','POST'])
@loginrequired
def userchangepassword():
form=ChangePasswordForm()
if form.validateonsubmit():
#They should enter their first password
#New password
#New password again
return rendertemplate('/passwordchange.html',form=form)
EDIT: Please check my new comment below. I updated the code.
/r/flask
https://redd.it/10isg81
Hi,
can you please explain how to create a password changer? After providing first password to the user, user should be able to change their fist password with their preference. So I created the code below. Could you please provide the necessary part?
@app.route("/changepassword",methods=['GET','POST'])
@loginrequired
def userchangepassword():
form=ChangePasswordForm()
if form.validateonsubmit():
#They should enter their first password
#New password
#New password again
return rendertemplate('/passwordchange.html',form=form)
EDIT: Please check my new comment below. I updated the code.
/r/flask
https://redd.it/10isg81
reddit
How to write a simple password changer?
Hi, can you please explain how to create a password changer? After providing first password to the user, user should be able to change their fist...