Storing Data / Object State Between URL's in a User Session
I am working to make a machine learning model / simulation web app, but am still pretty new to Flask. The model and simulation is a multi-step process and I'm struggling with the best way to handle data sharing across different url's within a user session. The workflow consists of:
​
* route(/index): User enters basic inputs into a webform
* These inputs are combined with a database table (every session will use the same data here), a quick model is trained, and a custom dataset for the current user's simulation is returned.
* The user is also automatically redirected to route(/simulation)
* This step requires \~10-15 seconds
* The returned custom dataset is \~25MB
​
* route(/simulation): User enters different parameters into a new webform, which are combined with the custom dataset generated from the previous step and a simulation is run that returns the final result
* This process should be iterative. The webform input parameters will be constantly updated, but the custom dataset generated in the first step will stay constant.
* This process should be as fast as possible. The simulation itself takes 1-2 seconds if the custom
/r/flask
https://redd.it/bcx6uj
I am working to make a machine learning model / simulation web app, but am still pretty new to Flask. The model and simulation is a multi-step process and I'm struggling with the best way to handle data sharing across different url's within a user session. The workflow consists of:
​
* route(/index): User enters basic inputs into a webform
* These inputs are combined with a database table (every session will use the same data here), a quick model is trained, and a custom dataset for the current user's simulation is returned.
* The user is also automatically redirected to route(/simulation)
* This step requires \~10-15 seconds
* The returned custom dataset is \~25MB
​
* route(/simulation): User enters different parameters into a new webform, which are combined with the custom dataset generated from the previous step and a simulation is run that returns the final result
* This process should be iterative. The webform input parameters will be constantly updated, but the custom dataset generated in the first step will stay constant.
* This process should be as fast as possible. The simulation itself takes 1-2 seconds if the custom
/r/flask
https://redd.it/bcx6uj
reddit
r/flask - Storing Data / Object State Between URL's in a User Session
0 votes and 0 comments so far on Reddit
[Ask Flask] Background update of a global dictionary shared between requests
I need to update a configuration dictionary of service (uri) lookups (< 1k entries) in the background of a flask app.
What’s the most lightweight way to achieve this?
I would like to keep everything in process and I don’t want to make another network request to something external.
It doesn’t matter if a dirty read is performed from the dictionary as the app is fault tolerant and will retry.
/r/flask
https://redd.it/bcxr3f
I need to update a configuration dictionary of service (uri) lookups (< 1k entries) in the background of a flask app.
What’s the most lightweight way to achieve this?
I would like to keep everything in process and I don’t want to make another network request to something external.
It doesn’t matter if a dirty read is performed from the dictionary as the app is fault tolerant and will retry.
/r/flask
https://redd.it/bcxr3f
reddit
r/flask - [Ask Flask] Background update of a global dictionary shared between requests
0 votes and 0 comments so far on Reddit
Algorithmic trading in less than 100 lines of Python code
https://www.oreilly.com/learning/algorithmic-trading-in-less-than-100-lines-of-python-code
/r/Python
https://redd.it/bcsntk
https://www.oreilly.com/learning/algorithmic-trading-in-less-than-100-lines-of-python-code
/r/Python
https://redd.it/bcsntk
O’Reilly Media
Algorithmic trading in less than 100 lines of Python code
If you're familiar with financial trading and know Python, you can get started with basic algorithmic trading in no time.
Formset: Saving Unchanged data
Formsets only pass changed fields via request.post to the post form.
There are fields in the form which are not changed but I want to post to a model.
These are new posts to a model and not changes to existing data.
For example:
Class Name(models.Model):
first_name = models.CharField(max_length=25)
last_name = models.CharField(max_length=25)
class NameForm(ModelForm):
class Meta:
model = Name
fields = '__all__'
if the first name is changed but not the last name; Only the first_name will be passed as last_name was not changed.
Given this, the form will not save because it is not valid; it is missing the last_name.
I believe setting 'has_changed' = True for all form fields will work but I am unsure how to do this.
So how do I get all the form data so it will be valid?
Thanks
/r/django
https://redd.it/bcwvn4
Formsets only pass changed fields via request.post to the post form.
There are fields in the form which are not changed but I want to post to a model.
These are new posts to a model and not changes to existing data.
For example:
Class Name(models.Model):
first_name = models.CharField(max_length=25)
last_name = models.CharField(max_length=25)
class NameForm(ModelForm):
class Meta:
model = Name
fields = '__all__'
if the first name is changed but not the last name; Only the first_name will be passed as last_name was not changed.
Given this, the form will not save because it is not valid; it is missing the last_name.
I believe setting 'has_changed' = True for all form fields will work but I am unsure how to do this.
So how do I get all the form data so it will be valid?
Thanks
/r/django
https://redd.it/bcwvn4
reddit
r/django - Formset: Saving Unchanged data
6 votes and 1 comment so far on Reddit
How to implement Django query filter using with AND
I'm trying to find a more efficient way to retrieve data from the database. My scenario is that I want to get a bunch of posts from the Post model based on the condition that the post must have a particular tag and that the post belongs to a person I follow and if the post belongs to such a person I shoud only get their public posts. Along with that, I want all of my posts too for that tag and if they are my posts, then I should get all public and private posts. Currently, I've come up with this Post.objects.filter(tags\_\_field = tag, owner\_id\_\_in= user\_ids, privacy\_setting\_\_in= privacy\_options) How can I use the and condition to get the result I want?
/r/django
https://redd.it/bcyf6h
I'm trying to find a more efficient way to retrieve data from the database. My scenario is that I want to get a bunch of posts from the Post model based on the condition that the post must have a particular tag and that the post belongs to a person I follow and if the post belongs to such a person I shoud only get their public posts. Along with that, I want all of my posts too for that tag and if they are my posts, then I should get all public and private posts. Currently, I've come up with this Post.objects.filter(tags\_\_field = tag, owner\_id\_\_in= user\_ids, privacy\_setting\_\_in= privacy\_options) How can I use the and condition to get the result I want?
/r/django
https://redd.it/bcyf6h
reddit
r/django - How to implement Django query filter using with AND
0 votes and 1 comment so far on Reddit
Dynaconf 2.0.0 is out! from dynaconf import settings
https://dev.to/rochacbruno/from-dynaconf-import-settings-2f8o
/r/flask
https://redd.it/bcftmh
https://dev.to/rochacbruno/from-dynaconf-import-settings-2f8o
/r/flask
https://redd.it/bcftmh
DEV Community
from dynaconf import settings
The only line of code you need to manage your Python 3 configurations
I converted MIT’s OpenCourseWare ”learn python course” to a layout which views better on all devices
I had been working on a project to give more depth to a YouTube playlist by allowing other media such as documents and sites all from the web. It morphed into this and one of my first personal projects using it was with MIT’s OpenCourseWare site. It just groups the URL’s and streams them from the creator.
First is my version of the Python course
[My version - introduction to python programming](https://collectyv.com/Course/saaaaaaab)
And now, MIT’s version.
[MIT’s version - Python Programming Course ](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/)
/r/Python
https://redd.it/bcxtwm
I had been working on a project to give more depth to a YouTube playlist by allowing other media such as documents and sites all from the web. It morphed into this and one of my first personal projects using it was with MIT’s OpenCourseWare site. It just groups the URL’s and streams them from the creator.
First is my version of the Python course
[My version - introduction to python programming](https://collectyv.com/Course/saaaaaaab)
And now, MIT’s version.
[MIT’s version - Python Programming Course ](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/)
/r/Python
https://redd.it/bcxtwm
MIT OpenCourseWare
Introduction to Computer Science and Programming in Python | Electrical Engineering and Computer Science | MIT OpenCourseWare
_6.0001 Introduction to Computer Science and Programming in Python_ is intended for students with little or no programming experience. It aims to provide students with an understanding of the role computation can play in solving problems and to help students…
Created a webapp that displays the bond-line structure of any chemical compound/molecule.
/r/Python
https://redd.it/bd355n
/r/Python
https://redd.it/bd355n
Feedback request: I published a 4-part series about python byte-code
[Part 1 - Intro](https://harpaz.wordpress.com/2018/09/15/python-byte-code-part-1-intro/)
[Part 2 - the Stack](https://harpaz.wordpress.com/2018/09/19/python-byte-code-part-2-the-stack/)
[Part 3 - Byte-code Tricks](https://harpaz.wordpress.com/2019/01/23/python-byte-code-part-3-byte-code-tricks/)
[Part 4 - Word-code Tricks](https://harpaz.wordpress.com/2019/04/13/python-byte-code-part-4-word-code-tricks/)
​
I would like to hear your opinion!
Tips and advice are always welcome :)
Thanks!
/r/Python
https://redd.it/bctzdz
[Part 1 - Intro](https://harpaz.wordpress.com/2018/09/15/python-byte-code-part-1-intro/)
[Part 2 - the Stack](https://harpaz.wordpress.com/2018/09/19/python-byte-code-part-2-the-stack/)
[Part 3 - Byte-code Tricks](https://harpaz.wordpress.com/2019/01/23/python-byte-code-part-3-byte-code-tricks/)
[Part 4 - Word-code Tricks](https://harpaz.wordpress.com/2019/04/13/python-byte-code-part-4-word-code-tricks/)
​
I would like to hear your opinion!
Tips and advice are always welcome :)
Thanks!
/r/Python
https://redd.it/bctzdz
Harpaz's blog
Python byte-code – Part 1 – Intro
I’ve been talking about Python’s byte-code for some time, but I haven’t really took the time to explain what it is and how it works, so here it goes! According to wikipedia –…
Did anyone took the Vue/Django Course and can recommend it?
[https://courses.djangowaves.com/](https://courses.djangowaves.com/)
​
I'm curious. Anyone took it can tell me if its worth it? I've always had issues with authentication and only found tutorials on how to do toy/demo apps.
/r/django
https://redd.it/bd68qb
[https://courses.djangowaves.com/](https://courses.djangowaves.com/)
​
I'm curious. Anyone took it can tell me if its worth it? I've always had issues with authentication and only found tutorials on how to do toy/demo apps.
/r/django
https://redd.it/bd68qb
Can I get a link to the django Discord Server?
A few days ago I removed the django discord server from my list, and I cant seem to find it again online. I imagined this one was the biggest. It had over 100 people on.
/r/django
https://redd.it/bd6ykp
A few days ago I removed the django discord server from my list, and I cant seem to find it again online. I imagined this one was the biggest. It had over 100 people on.
/r/django
https://redd.it/bd6ykp
reddit
r/django - Can I get a link to the django Discord Server?
0 votes and 0 comments so far on Reddit
models.py reserved names; list of all (if using Postgres)?
Ran into an issue earlier today where I was getting a `TypeError` of `int object is not callable` error when trying to save a new entry in a model in the Django admin. Turns out it was because I was using `save` as a field name, ie:
```
save = models.SmallIntegerField(default=0)
```
The error referenced line 1091 of `/usr/local/lib/python3.5/dist-packages/django/contrib/admin/options.py`, which in Django 2.1 is:
```
def save_model(self, request, obj, form, change):
"""
Given a model instance save it to the database.
"""
obj.save()
```
So it appears the `save` field name was overriding the `obj.save()` call above?
I found this:
[Field Name Restrictions](https://docs.djangoproject.com/en/2.2/topics/db/models/#field-name-restrictions)
But is there a list of all the reserved / protected words in Django `models.py`?
/r/django
https://redd.it/bd6o7q
Ran into an issue earlier today where I was getting a `TypeError` of `int object is not callable` error when trying to save a new entry in a model in the Django admin. Turns out it was because I was using `save` as a field name, ie:
```
save = models.SmallIntegerField(default=0)
```
The error referenced line 1091 of `/usr/local/lib/python3.5/dist-packages/django/contrib/admin/options.py`, which in Django 2.1 is:
```
def save_model(self, request, obj, form, change):
"""
Given a model instance save it to the database.
"""
obj.save()
```
So it appears the `save` field name was overriding the `obj.save()` call above?
I found this:
[Field Name Restrictions](https://docs.djangoproject.com/en/2.2/topics/db/models/#field-name-restrictions)
But is there a list of all the reserved / protected words in Django `models.py`?
/r/django
https://redd.it/bd6o7q
reddit
r/django - models.py reserved names; list of all (if using Postgres)?
0 votes and 2 comments so far on Reddit
[project] Anyone else is playing with reddit comments using ML in cloud? I'm trying to predict assholes judging from their karma from comments.
Fun categorical classification project, I'd call it ass-o-meter. I queried 1M 2019_01 comments from gbq and running my model on Google colab.
/r/MachineLearning
https://redd.it/bd26o7
Fun categorical classification project, I'd call it ass-o-meter. I queried 1M 2019_01 comments from gbq and running my model on Google colab.
/r/MachineLearning
https://redd.it/bd26o7
reddit
r/MachineLearning - [project] Anyone else is playing with reddit comments using ML in cloud? I'm trying to predict assholes judging…
133 votes and 80 comments so far on Reddit
Getting SQLAlchemy database instance in Flask
First of all, I'm sorry if this is longish but I can't describe the situation without being explicit, please bear with me.
​
I'm fairly new to flask and I'm building a simple blogging application and am quite confused of the whole application context thing but slowly grasping the concept of it, I want to know what is the better way of doing this which doesn't have any drawbacks. There are 'blog' and 'admin' blueprints for viewing and editing/adding/deleting blogs, respectively. Project layout is something like this:
​
main.py
config.cfg
database.db
blueprints/
--------admin/
------------__init__.py
------------routes.py
--------blog/
------------__init__.py
------------models.py
------------routes.py
I'm going to add another blueprint for 'user' objects and neatly organize everything in django-esque manner, because of this there are no references to main \`app\` object in \`blog.models\` because I don't think it's a good practice to import and define \`SQLAlchemy\` object in every \`models.py\` there might be in future, instead I'm using \`db.init\_app(app)\`
​
This is \`main.py\` file:
from flask import Flask
/r/flask
https://redd.it/bd6g85
First of all, I'm sorry if this is longish but I can't describe the situation without being explicit, please bear with me.
​
I'm fairly new to flask and I'm building a simple blogging application and am quite confused of the whole application context thing but slowly grasping the concept of it, I want to know what is the better way of doing this which doesn't have any drawbacks. There are 'blog' and 'admin' blueprints for viewing and editing/adding/deleting blogs, respectively. Project layout is something like this:
​
main.py
config.cfg
database.db
blueprints/
--------admin/
------------__init__.py
------------routes.py
--------blog/
------------__init__.py
------------models.py
------------routes.py
I'm going to add another blueprint for 'user' objects and neatly organize everything in django-esque manner, because of this there are no references to main \`app\` object in \`blog.models\` because I don't think it's a good practice to import and define \`SQLAlchemy\` object in every \`models.py\` there might be in future, instead I'm using \`db.init\_app(app)\`
​
This is \`main.py\` file:
from flask import Flask
/r/flask
https://redd.it/bd6g85
reddit
r/flask - Getting SQLAlchemy database instance in Flask
8 votes and 1 comment so far on Reddit
Why is pickling such a huge security problem? why is it so frowned upon?
I hear frequently that pickling shouldnt be used if it can be avoided because it is a security risk, but noone ever explains why? and ive tried googling security issues with pickling but i found mostly opinion articles shit talking it and no real tutorials or facts on how to exploit it, or how it could be exploited, or why it is so easy to exploit? can someone please explain to me some of the methods to exploit pickling and why its considered to such a bad practice in the cyber sec world?
/r/Python
https://redd.it/bd8lb0
I hear frequently that pickling shouldnt be used if it can be avoided because it is a security risk, but noone ever explains why? and ive tried googling security issues with pickling but i found mostly opinion articles shit talking it and no real tutorials or facts on how to exploit it, or how it could be exploited, or why it is so easy to exploit? can someone please explain to me some of the methods to exploit pickling and why its considered to such a bad practice in the cyber sec world?
/r/Python
https://redd.it/bd8lb0
reddit
r/Python - Why is pickling such a huge security problem? why is it so frowned upon?
15 votes and 11 comments so far on Reddit
redirecting pages on django
hi!
i know you guys hate noobs questions, but i suck at researching since english is not my first language and most times i cant find what i want.
on my website, i want to select an option on a dropdown and be redirected to another page with info about this option.
the thing is, i want to use the same template for all the options, only changing the content for each one.
i also want to keep the url like "[http://127.0.0.1:8000/areas/area+3"](http://127.0.0.1:8000/areas/area+3) where area+3 is the option selected (i already managed how to redirect to this url but can't make templates appear, not know how to pass data between pages also)
thanks for your patience!
/r/django
https://redd.it/bd8vi3
hi!
i know you guys hate noobs questions, but i suck at researching since english is not my first language and most times i cant find what i want.
on my website, i want to select an option on a dropdown and be redirected to another page with info about this option.
the thing is, i want to use the same template for all the options, only changing the content for each one.
i also want to keep the url like "[http://127.0.0.1:8000/areas/area+3"](http://127.0.0.1:8000/areas/area+3) where area+3 is the option selected (i already managed how to redirect to this url but can't make templates appear, not know how to pass data between pages also)
thanks for your patience!
/r/django
https://redd.it/bd8vi3
reddit
r/django - redirecting pages on django
6 votes and 2 comments so far on Reddit
Need Help Navigating To The Next and Previous URL Position
I am new to Django and I am using [https://github.com/justdjango/video-membership](https://github.com/justdjango/video-membership) to practice.
[https://imgur.com/aX944tV](https://imgur.com/aX944tV)
From lesson\_detail.html [https://github.com/justdjango/video-membership/tree/master/courses/templates/courses](https://github.com/justdjango/video-membership/tree/master/courses/templates/courses) I want to be able to navigate to the next and previous lesson video positions and their slugs and have a bit of logic that says that the first lesson only has next video (not previous video) displayed and the last lesson only has previous video (not next video) displayed. All other lessons in between the first and last lesson should have both next video and previous video displayed.
Any help would be greatly appreciated as I am unsure how to do this.
/r/django
https://redd.it/bd9qar
I am new to Django and I am using [https://github.com/justdjango/video-membership](https://github.com/justdjango/video-membership) to practice.
[https://imgur.com/aX944tV](https://imgur.com/aX944tV)
From lesson\_detail.html [https://github.com/justdjango/video-membership/tree/master/courses/templates/courses](https://github.com/justdjango/video-membership/tree/master/courses/templates/courses) I want to be able to navigate to the next and previous lesson video positions and their slugs and have a bit of logic that says that the first lesson only has next video (not previous video) displayed and the last lesson only has previous video (not next video) displayed. All other lessons in between the first and last lesson should have both next video and previous video displayed.
Any help would be greatly appreciated as I am unsure how to do this.
/r/django
https://redd.it/bd9qar
GitHub
GitHub - justdjango/video-membership: A basic video membership website built with Django and Stripe payments
A basic video membership website built with Django and Stripe payments - GitHub - justdjango/video-membership: A basic video membership website built with Django and Stripe payments
I don't know how everyone else learned Python, but the SoloLearn tutorial seems to have been a comprehensive introduction.
https://agentanakinai.wordpress.com/2019/04/15/python-3-tutorial-course/
/r/Python
https://redd.it/bdalsv
https://agentanakinai.wordpress.com/2019/04/15/python-3-tutorial-course/
/r/Python
https://redd.it/bdalsv
A.N.A.K.I.N.
Python
I have now completed SoloLearn’s introductory Python course.
Using flask-restful with blueprints producing an error
Hi all,
I'm a bit new at this but I'm trying to create a flask app and I have this kind of thing happening in my app.py file:
from flask import Flask
from flask_restful import Resource, Api
from apitest.blueprints.home import home
from apitest.blueprints.api import api_bp
def create_app():
"""
Create a Flask application using the app factory pattern.
:return: Flask app
"""
# instance_relative_config tells flask to look for an instance module that's in the same folder depth as the main module
app = Flask(__name__, instance_relative_config=True)
# look for a settings.py file in the config folder
app.config.from_object('config.settings')
# look in the instance folder for settings.py. Silent = True means don't crash if file doesn't exist
#
/r/flask
https://redd.it/bdcrgg
Hi all,
I'm a bit new at this but I'm trying to create a flask app and I have this kind of thing happening in my app.py file:
from flask import Flask
from flask_restful import Resource, Api
from apitest.blueprints.home import home
from apitest.blueprints.api import api_bp
def create_app():
"""
Create a Flask application using the app factory pattern.
:return: Flask app
"""
# instance_relative_config tells flask to look for an instance module that's in the same folder depth as the main module
app = Flask(__name__, instance_relative_config=True)
# look for a settings.py file in the config folder
app.config.from_object('config.settings')
# look in the instance folder for settings.py. Silent = True means don't crash if file doesn't exist
#
/r/flask
https://redd.it/bdcrgg
reddit
r/flask - Using flask-restful with blueprints producing an error
8 votes and 1 comment so far on Reddit