100 free Jupyter notebooks on interactive computing and data science
https://groups.google.com/forum/#!topic/jupyter/JHv0FhaggGc
/r/IPython
https://redd.it/88iqfe
https://groups.google.com/forum/#!topic/jupyter/JHv0FhaggGc
/r/IPython
https://redd.it/88iqfe
Is ALLOWED_HOSTS cross referenced with request.get_host()?
I'm slightly confused when it comes to how django is using the tuple in ALLOWED_HOSTS to validate host. Does django run request.get_host() and compare the host to the list within ALLOWED_HOSTS?
The django documentation indicates the following with regards to ALLOWED_HOSTS:
>This validation only applies via get_host(); if your code accesses the Host header directly from request.META you are bypassing this security protection.
>https://docs.djangoproject.com/en/2.0/ref/settings/
If I create middleware that uses get_host() to get the host and compare it to a list of approved host names and pass the user 404 if the domain isn't in the list, I assume this would essentially be replicating the ALLOWED_HOSTS functionality?
I ask this question because I do, in fact, need to write middleware to replace ALLOWED_HOSTS. The list of approved hosts grows over time as more users sign up. As a result, I the tuple that I'm validating against is dynamic and thus, I can't use the default ALLOWED_HOSTS config in django.
Thanks!
/r/django
https://redd.it/87yzer
I'm slightly confused when it comes to how django is using the tuple in ALLOWED_HOSTS to validate host. Does django run request.get_host() and compare the host to the list within ALLOWED_HOSTS?
The django documentation indicates the following with regards to ALLOWED_HOSTS:
>This validation only applies via get_host(); if your code accesses the Host header directly from request.META you are bypassing this security protection.
>https://docs.djangoproject.com/en/2.0/ref/settings/
If I create middleware that uses get_host() to get the host and compare it to a list of approved host names and pass the user 404 if the domain isn't in the list, I assume this would essentially be replicating the ALLOWED_HOSTS functionality?
I ask this question because I do, in fact, need to write middleware to replace ALLOWED_HOSTS. The list of approved hosts grows over time as more users sign up. As a result, I the tuple that I'm validating against is dynamic and thus, I can't use the default ALLOWED_HOSTS config in django.
Thanks!
/r/django
https://redd.it/87yzer
reddit
Is ALLOWED_HOSTS cross referenced with request.get_host()? • r/django
I'm slightly confused when it comes to how django is using the tuple in ALLOWED_HOSTS to validate host. Does django run request.get_host() and...
[Ask Flask] Trying to query a single value from FlaskSQLAlchemy/SQLite database and validate it for auth
Hello,
I have a USER table in my SQLite database which has only 1 user record. The table simply consists of ID, USERNAME, PASSWORD.
I am trying to query USERNAME and PASSWORD by defining **un** and **pw** variables as queries, and then check in my HTTP authentication if username == un and password == pw.
However, I haven't been able to get the queries I'm using for **un** and **pw** to just return the USERNAME and PASSWORD string values to use for comparison.
Can someone show me how I can get this working?
Thank you!
Here's the code. Pretty straightforward:
@app.route('/adicionar')
def adicionar():
un = db.session.query(User.username)
pw = db.session.query(User.password)
if request.authorization and request.authorization.username == un and request.authorization.password == pw:
return render_template('adicionar.html')
else:
return make_response('User not authorized', 401, {'WWW-Authenticate' : 'Basic realm = "Login Required"'})
EDIT: Additionally for troubleshooting, the below statement returns an error:
*TypeError: 'BaseQuery' object is not callable*
@app.route('/adicionar')
def adicionar():
un = db.session.query(User.username)
pw = db.session.query(User.password)
return pw
/r/flask
https://redd.it/88j63r
Hello,
I have a USER table in my SQLite database which has only 1 user record. The table simply consists of ID, USERNAME, PASSWORD.
I am trying to query USERNAME and PASSWORD by defining **un** and **pw** variables as queries, and then check in my HTTP authentication if username == un and password == pw.
However, I haven't been able to get the queries I'm using for **un** and **pw** to just return the USERNAME and PASSWORD string values to use for comparison.
Can someone show me how I can get this working?
Thank you!
Here's the code. Pretty straightforward:
@app.route('/adicionar')
def adicionar():
un = db.session.query(User.username)
pw = db.session.query(User.password)
if request.authorization and request.authorization.username == un and request.authorization.password == pw:
return render_template('adicionar.html')
else:
return make_response('User not authorized', 401, {'WWW-Authenticate' : 'Basic realm = "Login Required"'})
EDIT: Additionally for troubleshooting, the below statement returns an error:
*TypeError: 'BaseQuery' object is not callable*
@app.route('/adicionar')
def adicionar():
un = db.session.query(User.username)
pw = db.session.query(User.password)
return pw
/r/flask
https://redd.it/88j63r
reddit
[Ask Flask] Trying to query a single value from... • r/flask
Hello, I have a USER table in my SQLite database which has only 1 user record. The table simply consists of ID, USERNAME, PASSWORD. I am trying...
Getting CROSS JOIN with intermediate table with Django ORM?
Hi,
I have these models:
class Region(models.Model):
region_name = models.CharField(max_length=64)
def __str__(self):
return self.region_name
class GameRegionRelease(models.Model):
region = models.ForeignKey(
Region,
on_delete=models.CASCADE,
verbose_name='region'
)
game = models.ForeignKey(
Game,
on_delete=models.CASCADE,
verbose_name='game'
)
release_date = models.DateField(
verbose_name='release date',
default=None
)
class Game(models.Model):
game_name = models.CharField(max_length=512)
release_dates = models.ManyToManyField(
Region,
related_name='game_release_dates',
through='GameRegionRelease'
)
What I'm looking to get is every region listed for every game, even if there is no region data for that game. So the results would be Game x Region, with the region data filled in by GameRegionRelease where available. I'd want something similar to what the following would produce:
SELECT *
FROM gameslist_region gr
CROSS JOIN gameslist_game gg
LEFT JOIN gameslist_gameregionrelease grr
ON gg.game_name = grr.game_id
AND gr.region_name = grr.region_id;
But I don't know how to express this in Django using native ORM constructs. Is this possible? I'm using Python 3.6.4 and Django 2.0.2.
/r/django
https://redd.it/87vli4
Hi,
I have these models:
class Region(models.Model):
region_name = models.CharField(max_length=64)
def __str__(self):
return self.region_name
class GameRegionRelease(models.Model):
region = models.ForeignKey(
Region,
on_delete=models.CASCADE,
verbose_name='region'
)
game = models.ForeignKey(
Game,
on_delete=models.CASCADE,
verbose_name='game'
)
release_date = models.DateField(
verbose_name='release date',
default=None
)
class Game(models.Model):
game_name = models.CharField(max_length=512)
release_dates = models.ManyToManyField(
Region,
related_name='game_release_dates',
through='GameRegionRelease'
)
What I'm looking to get is every region listed for every game, even if there is no region data for that game. So the results would be Game x Region, with the region data filled in by GameRegionRelease where available. I'd want something similar to what the following would produce:
SELECT *
FROM gameslist_region gr
CROSS JOIN gameslist_game gg
LEFT JOIN gameslist_gameregionrelease grr
ON gg.game_name = grr.game_id
AND gr.region_name = grr.region_id;
But I don't know how to express this in Django using native ORM constructs. Is this possible? I'm using Python 3.6.4 and Django 2.0.2.
/r/django
https://redd.it/87vli4
reddit
Getting CROSS JOIN with intermediate table with Django ORM? • r/django
Hi, I have these models: class Region(models.Model): region_name = models.CharField(max_length=64) def __str__(self): ...
[af] Getting started with flask unit testing, tutorials?
I'm getting started on with unit testing. Are there any good tutorials that I should be aware of? Most of the ones I found online were either old or too basic. Right now I'm just referencing projects on Github and it's going OK. A nice tutorial would be helpful though.
/r/flask
https://redd.it/88lynb
I'm getting started on with unit testing. Are there any good tutorials that I should be aware of? Most of the ones I found online were either old or too basic. Right now I'm just referencing projects on Github and it's going OK. A nice tutorial would be helpful though.
/r/flask
https://redd.it/88lynb
reddit
[af] Getting started with flask unit testing, tutorials? • r/flask
I'm getting started on with unit testing. Are there any good tutorials that I should be aware of? Most of the ones I found online were either old...
What are the best practices for logging IP addresses?
Should I and to what extent should I log the IP addresses that hit my Flask web app (PostgreSQL, Flask-Security, Flask-Sqlalchemy) that is hosted in Heroku? It is an event planning web app that allows user account creation and the ability to RSVP through email links. Should I, for example, log the IP addresses that create user accounts or possibly the IP addresses that hit the RSVP page links that get sent after creating an event? Thanks in advance for any advice!
/r/flask
https://redd.it/88n0e1
Should I and to what extent should I log the IP addresses that hit my Flask web app (PostgreSQL, Flask-Security, Flask-Sqlalchemy) that is hosted in Heroku? It is an event planning web app that allows user account creation and the ability to RSVP through email links. Should I, for example, log the IP addresses that create user accounts or possibly the IP addresses that hit the RSVP page links that get sent after creating an event? Thanks in advance for any advice!
/r/flask
https://redd.it/88n0e1
reddit
What are the best practices for logging IP addresses? • r/flask
Should I and to what extent should I log the IP addresses that hit my Flask web app (PostgreSQL, Flask-Security, Flask-Sqlalchemy) that is hosted...
issue with Forms i wasn't having before
I formatted my computer, installed linux on it (was windows 7) and reinstalled the libraries, and now i started to getting error messages about flask_wtf.forms (or whatever) being deprecated.
I made some changes on my forms.py and i'm getting this error.
does anybody know what's the issue here?
https://imgur.com/a/MSX6v
/r/flask
https://redd.it/87o68j
I formatted my computer, installed linux on it (was windows 7) and reinstalled the libraries, and now i started to getting error messages about flask_wtf.forms (or whatever) being deprecated.
I made some changes on my forms.py and i'm getting this error.
does anybody know what's the issue here?
https://imgur.com/a/MSX6v
/r/flask
https://redd.it/87o68j
[P] Deep Reinforcement Learning Free Course
Hello, I'm currently writing a series of free articles about Deep Reinforcement Learning, where we'll learn the main algorithms (from Q* learning to PPO), and how to implement them in Tensorflow.
**The Syllabus**: https://simoninithomas.github.io/Deep_reinforcement_learning_Course/
The first article is published, each week 2 articles will be published, but **if you want to be alerted about the next article, follow me on Medium and/or follow the github repo below**
I wrote these articles because I wanted to have articles that begin with the big picture (understand the concept in simpler terms), then the mathematical implementation and finally a Tensorflow implementation **explained step by step** (each part of the code is commented). And too much articles missed the implementation part or just give the code without any comments.
Let me see what you think! What architectures you want and any feedback.
**The first article**: https://medium.freecodecamp.org/an-introduction-to-reinforcement-learning-4339519de419
**The first notebook**: https://github.com/simoninithomas/Deep_reinforcement_learning_Course/blob/master/Q%20learning/Q%20Learning%20with%20FrozenLake.ipynb
Thanks!
/r/MachineLearning
https://redd.it/88h0g4
Hello, I'm currently writing a series of free articles about Deep Reinforcement Learning, where we'll learn the main algorithms (from Q* learning to PPO), and how to implement them in Tensorflow.
**The Syllabus**: https://simoninithomas.github.io/Deep_reinforcement_learning_Course/
The first article is published, each week 2 articles will be published, but **if you want to be alerted about the next article, follow me on Medium and/or follow the github repo below**
I wrote these articles because I wanted to have articles that begin with the big picture (understand the concept in simpler terms), then the mathematical implementation and finally a Tensorflow implementation **explained step by step** (each part of the code is commented). And too much articles missed the implementation part or just give the code without any comments.
Let me see what you think! What architectures you want and any feedback.
**The first article**: https://medium.freecodecamp.org/an-introduction-to-reinforcement-learning-4339519de419
**The first notebook**: https://github.com/simoninithomas/Deep_reinforcement_learning_Course/blob/master/Q%20learning/Q%20Learning%20with%20FrozenLake.ipynb
Thanks!
/r/MachineLearning
https://redd.it/88h0g4
How do I synchronously wait for an asyncio future?
I can't just use `loop.run_until_complete` because my code is being called from an asyncio loop. I can't just make my function async because the thing calling my code (neovim remote plugin host) doesn't work that way (because it supports pyuv so it can work on python 2).
I can't do `asyncio.new_event_loop().run_until_complete` because apparently you can't run a loop while another loop is running. (Why not???? I don't understand.)
I've thought of starting a new thread so I can run a new loop in that thread, but **there *must* be a better way**.
/r/Python
https://redd.it/88mxto
I can't just use `loop.run_until_complete` because my code is being called from an asyncio loop. I can't just make my function async because the thing calling my code (neovim remote plugin host) doesn't work that way (because it supports pyuv so it can work on python 2).
I can't do `asyncio.new_event_loop().run_until_complete` because apparently you can't run a loop while another loop is running. (Why not???? I don't understand.)
I've thought of starting a new thread so I can run a new loop in that thread, but **there *must* be a better way**.
/r/Python
https://redd.it/88mxto
reddit
How do I synchronously wait for an asyncio future? • r/Python
I can't just use `loop.run_until_complete` because my code is being called from an asyncio loop. I can't just make my function async because the...
Is there something weird I don't understand with callbacks?
Hello,
I am learning python and did this quick exercise to familiarize myself with tkinter, lambdas, and callbacks. But it's behaving very weirdly. Here's the sample code:
def callback(col, val):
print("Hello: i=" + str(col) + ",j=" + str(val))
for i in range(10):
col = tkinter.Frame(frame)
for j in range(i):
button = tkinter.Button(col, height = 3, width = 5, text = str(j+1), command = lambda: callback(i, j))
button.pack(side = tkinter.TOP)
col.pack(side = tkinter.LEFT, anchor = tkinter.N, expand = False)
frame.pack()
top.mainloop()
The buttons get laid out properly and display the right thing. But when you click each one, rather than printing out the specific (i, j), they all print the same i and j (9 and 8) - as if they were all getting the same callback - the last callback defined. This is really surprising behavior, am I missing something?
Thank you!
/r/Python
https://redd.it/88ox3y
Hello,
I am learning python and did this quick exercise to familiarize myself with tkinter, lambdas, and callbacks. But it's behaving very weirdly. Here's the sample code:
def callback(col, val):
print("Hello: i=" + str(col) + ",j=" + str(val))
for i in range(10):
col = tkinter.Frame(frame)
for j in range(i):
button = tkinter.Button(col, height = 3, width = 5, text = str(j+1), command = lambda: callback(i, j))
button.pack(side = tkinter.TOP)
col.pack(side = tkinter.LEFT, anchor = tkinter.N, expand = False)
frame.pack()
top.mainloop()
The buttons get laid out properly and display the right thing. But when you click each one, rather than printing out the specific (i, j), they all print the same i and j (9 and 8) - as if they were all getting the same callback - the last callback defined. This is really surprising behavior, am I missing something?
Thank you!
/r/Python
https://redd.it/88ox3y
reddit
Is there something weird I don't understand with callbacks? • r/Python
Hello, I am learning python and did this quick exercise to familiarize myself with tkinter, lambdas, and callbacks. But it's behaving very...
Play Tetris inside a Jupyter notebook today!
http://www.juliatetris.com
/r/IPython
https://redd.it/88p097
http://www.juliatetris.com
/r/IPython
https://redd.it/88p097
[N] Introducing TensorFlow Hub: A Library for Reusable Machine Learning Modules in TensorFlow
https://medium.com/tensorflow/introducing-tensorflow-hub-a-library-for-reusable-machine-learning-modules-in-tensorflow-cdee41fa18f9
/r/MachineLearning
https://redd.it/88o922
https://medium.com/tensorflow/introducing-tensorflow-hub-a-library-for-reusable-machine-learning-modules-in-tensorflow-cdee41fa18f9
/r/MachineLearning
https://redd.it/88o922
Medium
Introducing TensorFlow Hub: A Library for Reusable Machine Learning Modules in TensorFlow
Posted by Josh Gordon, Developer Advocate for TensorFlow
Im new to Python, and I have Komodo IDE
Ive been looking to get into Learning Languages, and was recommended Python as a starting point. The following will sound stupid but I cant move past it.
I have been using Komodo IDE to start on with Python and am Following along Classes and Tutorials etc, one of the first things is Arithmetics.
On inputting 4 + 4 I do not get any output, am I doing something wrong? using cmd py -3 then 4 + 4 I get 8 as I should.
My question is what am I doing wrong to get no Output in Komodo? I get outputs for print(' ') etc.
Sorry for the dull question, thanks in advance for any help.
EDIT: Thanks for all the help, I have figured it out thanks to help. Appreciate it all :)
/r/Python
https://redd.it/88qjmn
Ive been looking to get into Learning Languages, and was recommended Python as a starting point. The following will sound stupid but I cant move past it.
I have been using Komodo IDE to start on with Python and am Following along Classes and Tutorials etc, one of the first things is Arithmetics.
On inputting 4 + 4 I do not get any output, am I doing something wrong? using cmd py -3 then 4 + 4 I get 8 as I should.
My question is what am I doing wrong to get no Output in Komodo? I get outputs for print(' ') etc.
Sorry for the dull question, thanks in advance for any help.
EDIT: Thanks for all the help, I have figured it out thanks to help. Appreciate it all :)
/r/Python
https://redd.it/88qjmn
reddit
Im new to Python, and I have Komodo IDE • r/Python
Ive been looking to get into Learning Languages, and was recommended Python as a starting point. The following will sound stupid but I cant move...
[AF] New to flask, every route is hitting the same function.
@app.route('/')
@app.route('/index')
@app.route('/login')
@app.route('/test')
def index():
print('hit index')
user = {'username': 'test'}
work.buildislandlist()
return render_template('index.html', user=user, island_list=work.island_list)
def login():
print('hit login')
form = LoginForm()
return render_template('login.html', title='Sign In?', form=form)
def test():
print("hit test")
return render_template('test.html')
So you can see I have those print statements in each function, and every time I hit /index, /login, /test on my browser, it only ever hits the index() function. Any ideas on why that may be?
/r/flask
https://redd.it/88rb2o
@app.route('/')
@app.route('/index')
@app.route('/login')
@app.route('/test')
def index():
print('hit index')
user = {'username': 'test'}
work.buildislandlist()
return render_template('index.html', user=user, island_list=work.island_list)
def login():
print('hit login')
form = LoginForm()
return render_template('login.html', title='Sign In?', form=form)
def test():
print("hit test")
return render_template('test.html')
So you can see I have those print statements in each function, and every time I hit /index, /login, /test on my browser, it only ever hits the index() function. Any ideas on why that may be?
/r/flask
https://redd.it/88rb2o
reddit
[AF] New to flask, every route is hitting the same function. • r/flask
@app.route('/') @app.route('/index') @app.route('/login') @app.route('/test') def index(): print('hit...
Transfer files over WiFi from your computer to your smartphone from the terminal
Here is project which I am really proud off. Please do suggest ways i could improve this project :)
Repo: https://github.com/sdushantha/qr-filetransfer
/r/Python
https://redd.it/88ra4o
Here is project which I am really proud off. Please do suggest ways i could improve this project :)
Repo: https://github.com/sdushantha/qr-filetransfer
/r/Python
https://redd.it/88ra4o
GitHub
GitHub - sdushantha/qr-filetransfer: Transfer files over WiFi between your computer and your smartphone from the terminal
Transfer files over WiFi between your computer and your smartphone from the terminal - sdushantha/qr-filetransfer
What's the coolest thing you did with Python?
Hello everyone.
I'm a beginner in Python and still doing a course on it. I just started Python just 2 months. I really want to motivate myself to continue learning Python, but I only learn the course on and off . I felt that only way to keep me going is be shown on how great and useful Python is. Yes, I do have a project I plan to do with the knowledge of Python, but just feel lazy sometimes (I really want to be very committed).I will really get inspired and motivated when I see the amazing things that Python can do and create. Please tell me your stories.
Also, you can mention how it was life changing.
Did it help make your job non related to programming easier?
Were your co-workers impressed by your skill and felt like they should learn too?
Did it help get you a job?
Thank you
/r/Python
https://redd.it/88w1ws
Hello everyone.
I'm a beginner in Python and still doing a course on it. I just started Python just 2 months. I really want to motivate myself to continue learning Python, but I only learn the course on and off . I felt that only way to keep me going is be shown on how great and useful Python is. Yes, I do have a project I plan to do with the knowledge of Python, but just feel lazy sometimes (I really want to be very committed).I will really get inspired and motivated when I see the amazing things that Python can do and create. Please tell me your stories.
Also, you can mention how it was life changing.
Did it help make your job non related to programming easier?
Were your co-workers impressed by your skill and felt like they should learn too?
Did it help get you a job?
Thank you
/r/Python
https://redd.it/88w1ws
reddit
What's the coolest thing you did with Python? • r/Python
Hello everyone. I'm a beginner in Python and still doing a course on it. I just started Python just 2 months. I really want to motivate myself to...
I wrote a complete beginner's guide to deploying a Django app on Google Cloud's Flexible App Engine (pics and deployment template files included)
https://medium.com/@vampiire/beginners-guide-to-deploying-a-django-postgresql-project-on-google-cloud-s-flexible-app-engine-e3357b601b91
/r/django
https://redd.it/88wcrn
https://medium.com/@vampiire/beginners-guide-to-deploying-a-django-postgresql-project-on-google-cloud-s-flexible-app-engine-e3357b601b91
/r/django
https://redd.it/88wcrn
Medium
Beginner’s Guide to Deploying a Django + PostgreSQL project on Google Cloud’s Flexible App Engine
A no-steps-skipped beginner’s guide to using Google Cloud for your first production Django app deployment.