Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
How to handle JWT authentication in a RESTful API with flask-praetorian (mainly logging users out and handling errors)?

Hi,

I am using [flask\-praetorian](http://flask-praetorian.readthedocs.io/en/latest/index.html), it works fine for logging a user in and protecting a route, but beyond that, I have no idea how to use it to accomplish other tasks like logging out users, handling errors...

For example, accessing a protected route results in the following exception \(with a `500` error instead of a` 40`1 error as it's supposed to\):

flask_praetorian.exceptions.MissingTokenHeader: JWT token not found in headers under 'Authorization' (401)

I am sure other errors \(like an invalid token\) have the same behavior. How can I return a custom message with the proper status code?

Also, I don't know much about JWT, I have read that keeping the user logged in with the same token for an extended period of time is a bad idea, so how can I allow logging out and token expiration? Do you guys have any resources I need to read before making an API with weak security?

Thanks!

/r/flask
https://redd.it/8dqbhl
Django Rest Framework + Vue.js - Live notifications like on the FB

I have a social network project written in Django Rest Framework + Vue.js. I need to add new feature - live notifications like on the Facebook. For example:

* user A commented your post

* user K started fallowing you


and much more actions.

What is the best way to do this? Any suggestions are very welcome.

/r/django
https://redd.it/8dqbz0
Creating a new molecule in ASE.

Been doing some searching on the internet and haven't found a good tutorial for my question:

I'm trying to model https://en.wikipedia.org/wiki/HMX using ASE try to optimize its geometry and it obviously isn't in the ase.collections.g2 database.

Can anyone point me in the right direction on where to get started making new molecules not in the ASE database?

Thank you and I apologize if this is in the incorrect subreddit.

/r/Python
https://redd.it/8dsgs6
Going from Matlab to Python?

I was wanting to hear some thoughts on how easy the transition is from Matlab to Python. I’d say I’m becoming sorta proficient in Matlab at this point, am I gonna have an easy time picking up Python with that background? I’m looking to mainly use it for stuff you’d see in engineering school like solving math problems and all that.

/r/Python
https://redd.it/8dtj7k
How do I move my Django project to Linode?

I have a Django project that works fine on my local machine. The project hooks up to a Postgres database. I want to move it to a Linode Debian instance. But I cannot find clear instructions on how to move my project to the Linode server. Anyone have experience moving a Django project to Linode? Got some pointers?

/r/django
https://redd.it/8dtbim
Minesweeper for command line [Linux]

/r/Python
https://redd.it/8dxorh
Issue: Text deletes when i type in front of it.

This just started happening a few days ago and I have never had this issue before. When I start typing code in front of a previous line of code it deletes it. For example, if a line has "print('Hello World!')" and I use my cursor to click in front of the word "print" and type "read", then it would be "readt('Hello World!')". Does anyone know how to fix this? Any help would be greatly appreciated.

/r/IPython
https://redd.it/8dxepo
A handy cheatsheet for Python
http://pysnippets.com

/r/Python
https://redd.it/8e1mzq
User Session and Session Data

Is there any way to store session data based on a User's session?

i.e. `request.user['foo'] = 'bar'`

I know the above code doesn't work, so I was wondering if there is something built in where you could individually store data in sessions with each user? Or is there another to do something like this, because I need to use data across different views and I need to keep it separate from each User.

/r/djangolearning
https://redd.it/8e1v8q
Impressed!

Fastest web development framework I have encountered till now.
Made a website in 24hours, which would have otherwise taken at least a week.
Thanks Flask!

/r/flask
https://redd.it/8e2o6e
What are the chances of a django site being hacked?

If you were to create a cms in Django what are the chances of it being hacked compared to using wordpress?

Would it be near impossible to get hacked via a vulnerability in your cms if nobody else has access other than you to your django source code?

What if you are lazy/don't know how to update django and python so you end up never updating django versions?

You like a look of a few apps on djangos site so add a few.. would this increase your chances of getting hacked? Does the django repository have a bad reputation of vulnerability plugins like the wordpress one?

*I ask these questions as someone with no knowledge of django but wanting to learn so I can create my own cms and move from wordpress to django.

Thanks in advance :)


/r/django
https://redd.it/8e29do
[P] Simple Tensorflow implementation of Multimodal Unsupervised Image-to-Image Translation (MUNIT)

/r/MachineLearning
https://redd.it/8e4765
Struggling with dynamic forms

I need a form that can dynamically create more fields. I have a select, and I need a number of additional parameters depending on the value of the select.

For example, imagine a select "numberOfParameters" and if the user selects 4, I want 4 new fields. This is made even worse by the fact that these are dependent selects: the options on the second select which generates more fields depends on what has been selected on the first one.

This is proving to be pretty challenging in django, is it safe to do this without forms.py in AJAX/JQuery (which is relatively easy)? Or is there a way to do it normally? (or should I just drop the idea altogether if it isn't safe).

Example of what I mean:

An application for selecting a way to travel to school.

* Users can select a school they go to.
* Depending on which school they choose there are different options for the travel, some school have busses, some only have cars, some even have boats.
* Depending on which way they want to travel, there are more options: trains have option for 1st or second class, cars have options for brand, but also for itinerary, type of fuel, type of music you want to listen to, and boats don't have any options at all.

Thanks for reading.

/r/django
https://redd.it/8e376d
How can I convert my Jupyter notebooks to organizable and searchable documentation such as devdocs.io?

Hello guys.I have thousands of code snippets and jupyter notebooks.I want to create easily, organizable, searchable documentation(such as devdocs.io) for this Jupyter notebooks.
Are there tools for doing this hard work for me?

/r/IPython
https://redd.it/8e6w43