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
Help understanding flask sessions

I'm working on a flask app, and so far I haven't added any extensions, but eventually I want to have it employ a workflow something like the following

1) user visits the webapp
2) user uploads some text
3) the upload occurs over a web socket, using flask-socketio, which will then stay open long enough to deliver some analysis of the text

My question is this, what do I have to do to support multiple people accessing the site and using this workflow concurrently? Is it in the sockets, is it in user sessions, do I need to add user accounts? It's just not clear to me how my app should most easily know "this is a new text analysis run, separate from other users' runs that may be occurring."

Also, if anyone can recommend the ideal server for this setup, that would be most appreciated. I know flask-socketio has recommendations, but I don't know how to choose one.

FYI I'm using python 2.7.12 and flask 0.10.1.

Thank you anyone who can help!!!



/r/flask
https://redd.it/693p4k
[AF] Which cache mechanism are you using?

Hi

I'm currently working on a rather big flask app and was wondering which cache mechanism you are using out there?

Are there many using flask-caching with redis/memcached or is there anything else recommended?

Thank you in advance

/r/flask
https://redd.it/68w7wj
Are there best practices for organizing methods between related models?

Hi everyone, I have been working with Django for a while and I really dig it. However I often feel I overcomplicate my code and get lost at determining where everthing is.

For example - one issue I am facing, and am hoping for some insight on, is the following.

I have an application that has Missions (a series of tasks) which get assigned to Members.

A simplified version of the code is
class Mission
title = Charfield
description = Textfield

class MemberMission
mission = Foreignkey to Mission
member = Foreignkey to Member (which is connected to User)
status = Charfield
custom_variables = Dictionaryfield. (holds other data about what they have done or not)


I just realized that I may want the mission description to depend on membermisson variables (eg. perhaps we give more time or less time or vary the reward based on these variables).

So, in the template, rather than showing the field mission.description, I should show a function (get_description) that pulls the description and modifies it based on the membermission data.

My question​ is this, where would a Django pro put this function?

Should it be on the Membermission
Eg) membermission.get_description()

Or should it be on the Mission
Eg) misson.get_description(membermission)

Or should I have it as a seperate function in some toolbox file (and put it into a template tag)
Eg) toolbox.get_description(membermission)

Or should I just find a source for Adderall and get over all this?

Thank you so much everyone.

/r/django
https://redd.it/696rdp
Do you wanna join to build a python documentation (a.k.a learn python with me)?

[Official python documentation](https://docs.python.org/2/) is great. [learnpythonthehardway](https://learnpythonthehardway.org/) and [python in tutorialspoint](https://www.tutorialspoint.com/python/) are very good too. With three years coding python, I'm writing my notes here [http://magizbox.com/training/python/site/](http://magizbox.com/training/python/site/). However, I found that no one care about this site.

So I write this text for beginner python programmers, do you find anything helpful in my website, do you wanna join with me to build a better and more useful documentation. With experienced programmers, would you please give me some advice to make my notes more useful for other programmers?

Thank all of you so much.

/r/Python
https://redd.it/695xtr
[Ask Flask] Is it possible to Auto generate a form thats based off a Database Schema onto a web page using WTForms and SQLAlchemy?

I want to make a simple web application that is a able to look at the fields of a database and generate a form onto a page for a user to fill in.

Im relatively new to Flask and thought It would be maybe possible by using SQLAlchemy and WTForms but wanted to get a second opinion as to what might be the best and easiest way to do this. Also, if you know any documentation that might be of use to me to get this done, can you please share. Thanks!

/r/flask
https://redd.it/696ivi
[Ask Flask] When running from terminal script, it opens two webpages instead of one

Hello, I've found almost the same question on stackoverflow but without accepted response. This is unresolved and after 3 hours I'm at my limit.

What do I have:

- `run.py` in `/this/location/run.py`
- `issues` symbolic link in `~/bin/issues --> /this/location/run.py`

What I want:

- user opens a terminal and writes `issues`, that starts a flask app and opens a google-chrome browser (one).

What it does:

- user opens a terminal, writes `issues`, that stats flask app, opens a browser, re-starts flask I think and opens another browser...

**`run.py`**:

#!/usr/bin/env python3
from flask import Flask
import webbrowser
from multiprocessing import Process
app = Flask(__name__)

@app.route('/')
def index():
return 'Index Page'

@app.route('/hello')
def hello():
return 'Hello, World'

def start_server(url):
print("START SERVER")
app.run(host="{}".format(url), debug=True)

def start_browser(url, port):
webbrowser.open_new("http://{url}:{port}/".format(url=url, port=port))

def main():
url, port = '0.0.0.0', '5000'
p1 = Process(target=start_server, args=(url,))
p2 = Process(target=start_browser, args=(url, port))

processes = list()
processes.append(p1)
processes.append(p2)

for p in processes:
p.start()

if __name__ == '__main__':
main()

**Terminal output:**:

(SonGokussj4@my_secret_machine) - (~) $ issues
START SERVER
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
START SERVER
* Debugger is active!
* Debugger pin code: 165-476-411
127.0.0.1 - - [04/May/2017 16:53:48] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [04/May/2017 16:53:49] "GET / HTTP/1.1" 200 -

Anyone knows what the hell is happening?

/r/flask
https://redd.it/6980g8
Why does default=False have to be explicitly set for BooleanField in models.py?

I have a number of fields in my models.py file which have "= models.BooleanField()" set.

However, 'makemigrations' is rejecting them, saying that the non-nullable field needs a default. I thought the default for BooleanField was False?

I can fix the problem by adding (default=False) to every single BooleanField but it seems ridiculous that I have to do this.

Might there be a simpler way to solve this problem?

Robert

/r/django
https://redd.it/699k83
How have you automated your life with python? (if you have)

Hi, I'm learning python and need some inspiration. I saw another post on here but it was over 2 years old.

/r/Python
https://redd.it/69ba93
[AF] New project, site like Issue Tracker

Hello! For starters, I did do the `Mega-tutorial Part I` and some other tutorials like 2 months ago. But still don't understand a lot of things.

**What I need:**

- user writes into terminal`issues`, this starts a flask app in our company shared local diskspace where it will be saved.
- Chrome/Firefox will open and asks the user to enter `ANSA` and `META` PDF files (he will click on dots and choose the file, not write a path. Too complicated for them.
- Then they push a `process` button that will call a function `pdf_to_issues(ANSAfile, METAfile)` saved in some specific folder
- this script returns a LOT of issues in form of list: `['ANSA-34123', 'ANSA-35349', 'META-13303', '#44001', ...]`
- Flask would somehow load this list and compare it with already saved issues. If some of them are the same, it will tag them as `resolved`
- The user will see a list of issues that were resolved.
- Then he click on `View all issues` which will display a table of all saved issues and give red (unresolved) and green (resolved).
- In the future, user can edit those issues and modify `description`, `priority`.

[Here is a picture](http://i.imgur.com/6GuNPnJ.png) I did to somehow illuminate what I want.

I would be *grateful* for any help, pointers, where do I start, what libraries do I use, what articles do I read, what do I expect that would go wrong, anything. This will be my first Flask bigger project. Any help would be really appreciated.

Thanks!!!



/r/flask
https://redd.it/69atvr
[Ask Flask] is it possible to POST without moving?

I'm working on a mild app that uses form POST to send data to Flask, but can't figure out if there's a way to post in pure HTML / CSS without moving to the new page, being the POST page.

Is there?

/r/flask
https://redd.it/697mhq
Require login for entire site?

I found [this](http://onecreativeblog.com/post/59051248/django-login-required-middleware#code) blogpost, but it's very old. Is this still a viable approach or are there better alternatives?


/r/djangolearning
https://redd.it/67mjq9