Best practices with captchas - Am I doing this right?
I got application with server-side sessions. When user comes, I will generate captcha image server-side and set the solution as one of session variables.
This way, when the user submits the captcha, I will simply compare the solution to the saved session variable.
This works fine in testing single-threadedly using sqlite in memory as database but when in production using several workers and postgresql for the sessions, the validation fails from time to time several times in a row.
I am suspecting some kind of caching between my app and database messes up with the logic.
Is this bad way to implement captchas? What would be better way?
/r/flask
https://redd.it/7b5cii
I got application with server-side sessions. When user comes, I will generate captcha image server-side and set the solution as one of session variables.
This way, when the user submits the captcha, I will simply compare the solution to the saved session variable.
This works fine in testing single-threadedly using sqlite in memory as database but when in production using several workers and postgresql for the sessions, the validation fails from time to time several times in a row.
I am suspecting some kind of caching between my app and database messes up with the logic.
Is this bad way to implement captchas? What would be better way?
/r/flask
https://redd.it/7b5cii
reddit
Best practices with captchas - Am I doing this right? • r/flask
I got application with server-side sessions. When user comes, I will generate captcha image server-side and set the solution as one of session...
6 Experts share amazing ways a beginner can learn Python programming.
https://coolpythoncodes.com/best-way-learn-python-programming/
/r/Python
https://redd.it/7f9bpb
https://coolpythoncodes.com/best-way-learn-python-programming/
/r/Python
https://redd.it/7f9bpb
Suggestions for a python IDE for a relatively new developer
I know that most of you will react with "Here we go again... another IDE post...", but bare with me here please.
I am relatively new to python and I was using PyCharm up until yesterday, when I switched from Windows 10 to Fedora 27. Right now I am hesitating, whether to install PyCharm again or not. Why?
1. Ate my memory.
2. I am using docker and I felt I did not use PyCharm to it's fullest potential, because I was running it from the terminal :/.
Prior to writing the post, I did read multiple other IDE posts ( there are a lot of them, so if I lose some karma points today, I will understand) and people mostly suggested Spyder and VIM (some were advising to stay as far away as possible from VIM tho).
Long story short, after reading numerous threads on this topic, I could not decide, as everyone suggested something different and not everyone was in my position with the docker and "amazing" developer skills.
I would be grateful if you could give your humble opinions on the different python IDEs and a small recommendation that can help me pick one :).
/r/Python
https://redd.it/7fa34z
I know that most of you will react with "Here we go again... another IDE post...", but bare with me here please.
I am relatively new to python and I was using PyCharm up until yesterday, when I switched from Windows 10 to Fedora 27. Right now I am hesitating, whether to install PyCharm again or not. Why?
1. Ate my memory.
2. I am using docker and I felt I did not use PyCharm to it's fullest potential, because I was running it from the terminal :/.
Prior to writing the post, I did read multiple other IDE posts ( there are a lot of them, so if I lose some karma points today, I will understand) and people mostly suggested Spyder and VIM (some were advising to stay as far away as possible from VIM tho).
Long story short, after reading numerous threads on this topic, I could not decide, as everyone suggested something different and not everyone was in my position with the docker and "amazing" developer skills.
I would be grateful if you could give your humble opinions on the different python IDEs and a small recommendation that can help me pick one :).
/r/Python
https://redd.it/7fa34z
reddit
Suggestions for a python IDE for a relatively new developer • r/Python
I know that most of you will react with "Here we go again... another IDE post...", but bare with me here please. I am relatively new to python...
JupyterCon 2017 – Jupyter Blog
https://blog.jupyter.org/enjoy-jupytercon-2017-on-youtube-670e5ee606a8
/r/IPython
https://redd.it/7f7spx
https://blog.jupyter.org/enjoy-jupytercon-2017-on-youtube-670e5ee606a8
/r/IPython
https://redd.it/7f7spx
Jupyter Blog
Enjoy JupyterCon 2017 on YouTube
About a year ago the Jupyter team started a partnership with O’Reilly Media and NumFOCUS to organize JupyterCon 2017, the first in a series…
[AF] Apache deployment questions
After a bit of struggling with mod_wsgi, I've successfully deployed my first flask app on EC2!
However, once I set up my apache virtual host configuration, I started getting a 404 on my domain in browser (flask routes work, though). I realize this is because of how I set up my virtual host config, but I'm trying to figure out what the best way to deliver the pages is (different apache configuration, serve everything through flask, or maybe something else).
I have an EC2 instance running apache and mod_wsgi to serve my flask app with the following vhost.confd:
<VirtualHost *:80>
ServerName domain.com
WSGIDaemonProcess flask_app user=username group=groupname threads=5
WSGIScriptAlias / /var/www/flask_app/deploy.wsgi
<directory /var/www/flask_app>
WSGIProcessGroup flask_app
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
</directory>
</VirtualHost>
I think what I would like to do is just have apache serve up var/www/html when someone goes to domain.com, but have the flask traffic routed to something like domain.com/flask_traffic/name_of_route or flask.domain.com/name_of_route.
Is it possible to route traffic that way with a different apache configuration?
I've also considered just having my API traffic go to a different port, or serving all of my static content with Flask, but I'm not confident either of those are good solutions.
/r/flask
https://redd.it/7fbfs1
After a bit of struggling with mod_wsgi, I've successfully deployed my first flask app on EC2!
However, once I set up my apache virtual host configuration, I started getting a 404 on my domain in browser (flask routes work, though). I realize this is because of how I set up my virtual host config, but I'm trying to figure out what the best way to deliver the pages is (different apache configuration, serve everything through flask, or maybe something else).
I have an EC2 instance running apache and mod_wsgi to serve my flask app with the following vhost.confd:
<VirtualHost *:80>
ServerName domain.com
WSGIDaemonProcess flask_app user=username group=groupname threads=5
WSGIScriptAlias / /var/www/flask_app/deploy.wsgi
<directory /var/www/flask_app>
WSGIProcessGroup flask_app
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
</directory>
</VirtualHost>
I think what I would like to do is just have apache serve up var/www/html when someone goes to domain.com, but have the flask traffic routed to something like domain.com/flask_traffic/name_of_route or flask.domain.com/name_of_route.
Is it possible to route traffic that way with a different apache configuration?
I've also considered just having my API traffic go to a different port, or serving all of my static content with Flask, but I'm not confident either of those are good solutions.
/r/flask
https://redd.it/7fbfs1
Sending a file via POST using Django using Javascript instead of HTML Form (X-post from /r/webdev)
I have a PDF file saved in a variable 'report.'
I am using Django and want to pass it to a function in my views.py file using POST --
@xframe_options_exempt
@csrf_exempt
def process_report(request):
if request.method == 'POST'
report_file = request.FILES['docfile']
....
return response
How can I send a ajax POST request with this file? The filetype is a PDF.
I was using an HTML form to do this before, but I wanted to style the form upload using javascript. I tried styling the button using javascript (changing colors and text depending on file type uploaded), but the file was no longer being able to be passed through the POST request. Now I just have the file saved in a javascript variable, and am trying to just pass it via POST without using form. I understand it's impossible to prepopulate a form with a file.
My old code:
<form id="boring" action="{% url "process_report" %}" method="post"
enctype="multipart/form-data">
{% csrf_token %}
{{ form.non_field_errors }}
{{ form.docfile.label_tag }} {{ form.docfile.help_text }
{{ form.docfile.errors }}
{{ form.docfile }}
</form>
What I have been trying to do with ajax
var formdata = new FormData(report);
$.ajax({
url: 'process_report',
type: 'POST',
processData: false,
contentType: false,
dataType : 'application/pdf',
data: {
'content': 'formdata',
'csrfmiddlewaretoken': '{{ csrf_token }}',
}
/r/djangolearning
https://redd.it/7fcdfi
I have a PDF file saved in a variable 'report.'
I am using Django and want to pass it to a function in my views.py file using POST --
@xframe_options_exempt
@csrf_exempt
def process_report(request):
if request.method == 'POST'
report_file = request.FILES['docfile']
....
return response
How can I send a ajax POST request with this file? The filetype is a PDF.
I was using an HTML form to do this before, but I wanted to style the form upload using javascript. I tried styling the button using javascript (changing colors and text depending on file type uploaded), but the file was no longer being able to be passed through the POST request. Now I just have the file saved in a javascript variable, and am trying to just pass it via POST without using form. I understand it's impossible to prepopulate a form with a file.
My old code:
<form id="boring" action="{% url "process_report" %}" method="post"
enctype="multipart/form-data">
{% csrf_token %}
{{ form.non_field_errors }}
{{ form.docfile.label_tag }} {{ form.docfile.help_text }
{{ form.docfile.errors }}
{{ form.docfile }}
</form>
What I have been trying to do with ajax
var formdata = new FormData(report);
$.ajax({
url: 'process_report',
type: 'POST',
processData: false,
contentType: false,
dataType : 'application/pdf',
data: {
'content': 'formdata',
'csrfmiddlewaretoken': '{{ csrf_token }}',
}
/r/djangolearning
https://redd.it/7fcdfi
reddit
Sending a file via POST using Django using... • r/djangolearning
I have a PDF file saved in a variable 'report.' I am using Django and want to pass it to a function in my views.py file using POST -- ...
Getting started with Python for R developers
http://n-s-f.github.io/2017/03/25/r-to-python.html
/r/Python
https://redd.it/7fc4q1
http://n-s-f.github.io/2017/03/25/r-to-python.html
/r/Python
https://redd.it/7fc4q1
n-s-f.github.io
Getting started with Python for R developers
If you work in R and are curious about using Python, but haven’t quite known howto get started, this blog post is for you. I’ve come across quite a few R use...
Python Top 10 Articles - Nov 2017
https://medium.com/@Mybridge/python-top-10-articles-for-the-past-month-v-nov-2017-f46fcaa36e4b
/r/Python
https://redd.it/7fdv49
https://medium.com/@Mybridge/python-top-10-articles-for-the-past-month-v-nov-2017-f46fcaa36e4b
/r/Python
https://redd.it/7fdv49
Medium
Python Top 10 Articles for the Past Month (v.Nov 2017)
For the past month, we ranked nearly 1,000 Python articles to pick the Top 10 stories that can help advance your career (1% chance).
[AF][Flask-SQLAlchemy] How do I execute this query?
Hello, everyone!
I have the following relationship ([shitty diagram](https://i.imgur.com/QXgidVX.png)) and would like to fetch row(s) from the `Payments` table. Now obviously, what gets returned is `(id, employer_id, employee_id, payment_date)`. What is the correct way to fetch `(id, employer_name, employee_name, payment_date)`?
What I currently have:
# views.py
@app.route("/dashboard")
@login_required
def dashboard():
payments = Payment.query.all()
# TODO: Find a 'cleaner' way to fetch the relevant info for payments.
for payment in payments:
payment.employee_name = Employee.query.filter_by(id=payment.employee_id).first().name
payment.employer_name = Employer.query.filter_by(id=payment.employer_id).first().name
return render_template("dashboard.html", payments=payments)
---
# dashboard.html
...
<tbody>
{% for payment in payments %}
<tr>
<td>{{ payment.id }}</td>
<td>{{ payment.employer_name }}</td>
<td>{{ payment.employee_name }}</td>
<td>{{ payment.payment_date }}</td>
</tr>
{% endfor %}
</tbody>
Admittedly, I don't have much knowledge about databases aside from the basic ORM commands. I don't even know the correct terms to search for! Anyway, I'd like to know:
1. What is the correct way of doing what I did with the above code?
2. What would it look like in plain SQL?
3. What topics should I be reading up on?
Thanks a lot, r/flask!
/r/flask
https://redd.it/7aqvcl
Hello, everyone!
I have the following relationship ([shitty diagram](https://i.imgur.com/QXgidVX.png)) and would like to fetch row(s) from the `Payments` table. Now obviously, what gets returned is `(id, employer_id, employee_id, payment_date)`. What is the correct way to fetch `(id, employer_name, employee_name, payment_date)`?
What I currently have:
# views.py
@app.route("/dashboard")
@login_required
def dashboard():
payments = Payment.query.all()
# TODO: Find a 'cleaner' way to fetch the relevant info for payments.
for payment in payments:
payment.employee_name = Employee.query.filter_by(id=payment.employee_id).first().name
payment.employer_name = Employer.query.filter_by(id=payment.employer_id).first().name
return render_template("dashboard.html", payments=payments)
---
# dashboard.html
...
<tbody>
{% for payment in payments %}
<tr>
<td>{{ payment.id }}</td>
<td>{{ payment.employer_name }}</td>
<td>{{ payment.employee_name }}</td>
<td>{{ payment.payment_date }}</td>
</tr>
{% endfor %}
</tbody>
Admittedly, I don't have much knowledge about databases aside from the basic ORM commands. I don't even know the correct terms to search for! Anyway, I'd like to know:
1. What is the correct way of doing what I did with the above code?
2. What would it look like in plain SQL?
3. What topics should I be reading up on?
Thanks a lot, r/flask!
/r/flask
https://redd.it/7aqvcl
Making a test with django
I'm trying to make a political test with Django.
Luckily, the official tutorial deals with a pretty similar concept- making a "polls" app.
I have been trying to use the Django API for a bit now but I haven't been successful. Unlike the polls app, all my questions in my test will have the same five choices:
* Strongly Agree
* Agree
* Neutral/Don't know
* Disagree
* Strongly Agree
How would I make it so that when I create a new Question, it is automatically assigned those 5 options as a choice, rather than individually assigning the choices per question? This is important because the test will need to store and track how many times "Agree" was chosen, so it has to be the same variable, if that makes sense.
Thanks
/r/djangolearning
https://redd.it/7f023w
I'm trying to make a political test with Django.
Luckily, the official tutorial deals with a pretty similar concept- making a "polls" app.
I have been trying to use the Django API for a bit now but I haven't been successful. Unlike the polls app, all my questions in my test will have the same five choices:
* Strongly Agree
* Agree
* Neutral/Don't know
* Disagree
* Strongly Agree
How would I make it so that when I create a new Question, it is automatically assigned those 5 options as a choice, rather than individually assigning the choices per question? This is important because the test will need to store and track how many times "Agree" was chosen, so it has to be the same variable, if that makes sense.
Thanks
/r/djangolearning
https://redd.it/7f023w
reddit
Making a test with django • r/djangolearning
I'm trying to make a political test with Django. Luckily, the official tutorial deals with a pretty similar concept- making a "polls" app. I...
[P] I made a movie recommendation system in C as my first ML project in University
https://imgur.com/a/dk3IY
/r/MachineLearning
https://redd.it/7fa5hk
https://imgur.com/a/dk3IY
/r/MachineLearning
https://redd.it/7fa5hk
Imgur
Movie Recommendation System using C
Imgur: The most awesome images on the Internet.