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
Flask timeout on Raspberry Pi?

Hey folks,

I have the below code running perpetually on my local network, hosted on my Pi. Its just a super simple app for using the Pi as a WOL server, but after a few days (maybe a week?) its inaccessible on my local network, and I have to restart the code on the Pi. Does flask auto shutdown after a certain amount of time or something? I've got a feeling the answer is no, but this has happened 2-3 times now so I thought I'd make a post to see if anyone has the same issue.

from flask import Flask

app = Flask(__name__)

@app.route('/')
def home():
'WOL Code here'
Return 'WOL activated'

if __name__ == '__main__':
app.run(host='0.0.0.0', port=3000)


/r/flask
https://redd.it/7gdfpm
Please rate and/or learn from my (form processing) code

I am a self-taught programmer and I just realized that, after sitting alone by myself all this time typing into my computer, I'm not entirely sure I have any idea what I'm doing as I have never had anyone ever see my code or offer any constructive criticism to how I've grown to do things.

I'd really appreciate if anyone could have a look at my code linked below and just let me know if anything crazy pops out at you. It's pretty close to how I usually do things as far as importing and instantiating classes and whatnot.

this code in particular is for processing a user sign-up form:
https://gist.github.com/anonymous/0ca1188bf5c3f7a33a2fff080107004b

/r/flask
https://redd.it/7gidq4
[AF] Post request working locally, but not remotely.

Hi all, I'm new to Flask (and web programming in general, so please excuse me if this is the wrong place) and am simply trying to use it to work as something my Raspberry Pi can use to receive input from the internet.

Anyway, here's the issue. I've set up a small page that has an html form (a text box and a submit button), so I think this should be generating a post request. Basically, the input from the form gets passed to some other python code (blinks an LED).

When I run the website to be accessible locally, I can enter the input, press the submit on the actual page and everything behaves as expected. Similarly, I can use curl and send the input as the body of a post request.

When I run the website to accessible remotely (I turn off debug and change the port to the one I've forwarded), I can navigate to the page (I have a domain name via no-ip) and enter the input in the box and press submit, and it works. However, when I try to submit the request via curl (i update the target to be the URL from noip rather than the local ip of the pi), it just hangs until it times out, and I see nothing happening on the computer that sent the request, or the pi running the flask server. When I try to submit the request via IFTTT, I do see that the server has a received a request, but I get a 400 error.

Im guessing this is a bug with NoIP, rather than flask, but I'm unsure of how to even go about debugging. Flask gurus, do you have any ideas here?

/r/flask
https://redd.it/7geqag
Double underscore method for ordering the list returned by the view based on a field in another model not working

I'm trying to order the list the view returns based on a field in another model. I read the [documentation over here](https://docs.djangoproject.com/en/1.11/ref/models/querysets/#order-by) and it says I could do that by using the model's name, if the ordering is specified in the model's meta.

**View**

class ResultsView(generic.DetailView):
model = Question
template_name = 'polls/results.html'
ordering = ['choice']


**Model**

class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)

def __str__(self):
return self.choice_text

class Meta:
ordering = ['-votes']

I did that, it works but I have different views which require the same model to be ordered in different ways, say one by it's name and another by votes. How can I achieve something like that?

For example I am looking for something like

**View 1**

class ResultsView(generic.DetailView):
model = Question
template_name = 'polls/results.html'
ordering = ['-choice__votes']

**View 2**

class DetailView(generic.DetailView):
model = Question
template_name = 'polls/detail.html'
ordering = ['-choice__choice_text']

/r/djangolearning
https://redd.it/7gj6xz
Share your Apps/Websites created using Django? We need motivation!

Please provide with information such as:

Website Link:

Active Users:

Monthly Revenue Generation:

Website details, and target Costumer:

Important things Learned while creating your website:

Packages/Libraries used:


Thank you for sharing.

/r/django
https://redd.it/7gldnw
What is the first interesting program you made with python?

I created the bounce game (Python for kids) today. It's the game we played in our childhood where the ball used to move randomly and we had to save it from hitting the bottom. Not that big of a deal for some, but good enough for me. Have been working with Django for an year now, but this is way more fun than building scalable websites or analyzing data. What is your first exciting moment with python?

/r/Python
https://redd.it/7gm1ze
When I create a new Flask project, here are 15 libraries that are always in my requirements.txt file. What libraries do you use?

I find myself using these libraries in every new Flask project I set up:

* gunicorn
* flask-debugtoolbar
* pytest and pytest-cov
* flake8
* Flask-SQLAlchemy and psycopg2
* alembic
* celery and redis
* Flask-WTF and WTForms-Components
* Flask-Login
* Flask-Limiter
* Flask-Mail

If you want to know why I use all of these libraries, more details can be found at
https://nickjanetakis.com/blog/15-useful-flask-extensions-and-libraries-that-i-use-in-every-project.

What's your favorite extensions and libraries?

/r/flask
https://redd.it/7g4wzg
When I create a new Flask project, here are 15 libraries that are always in my requirements.txt file. What libraries do you use?

I find myself using these libraries in every new Flask project I set up:

* gunicorn
* flask-debugtoolbar
* pytest and pytest-cov
* flake8
* Flask-SQLAlchemy and psycopg2
* alembic
* celery and redis
* Flask-WTF and WTForms-Components
* Flask-Login
* Flask-Limiter
* Flask-Mail

If you want to know why I use all of these libraries, more details can be found at
https://nickjanetakis.com/blog/15-useful-flask-extensions-and-libraries-that-i-use-in-every-project.

What's your favorite extensions and libraries?

/r/flask
https://redd.it/7g4wzg
When I create a new Flask project, here are 15 libraries that are always in my requirements.txt file. What libraries do you use?

I find myself using these libraries in every new Flask project I set up:

* gunicorn
* flask-debugtoolbar
* pytest and pytest-cov
* flake8
* Flask-SQLAlchemy and psycopg2
* alembic
* celery and redis
* Flask-WTF and WTForms-Components
* Flask-Login
* Flask-Limiter
* Flask-Mail

If you want to know why I use all of these libraries, more details can be found at
https://nickjanetakis.com/blog/15-useful-flask-extensions-and-libraries-that-i-use-in-every-project.

What's your favorite extensions and libraries?

/r/flask
https://redd.it/7g4wzg
When I create a new Flask project, here are 15 libraries that are always in my requirements.txt file. What libraries do you use?

I find myself using these libraries in every new Flask project I set up:

* gunicorn
* flask-debugtoolbar
* pytest and pytest-cov
* flake8
* Flask-SQLAlchemy and psycopg2
* alembic
* celery and redis
* Flask-WTF and WTForms-Components
* Flask-Login
* Flask-Limiter
* Flask-Mail

If you want to know why I use all of these libraries, more details can be found at
https://nickjanetakis.com/blog/15-useful-flask-extensions-and-libraries-that-i-use-in-every-project.

What's your favorite extensions and libraries?

/r/flask
https://redd.it/7g4wzg
Sports statistic site

Hi,

I’m a newish full stack developer and I’m trying to build a sports statistic site in Django.

I’m struggling with working out how to structure my project with regards to both the models and the apps I use.

It is a basketball focused application so I’ve started with a player model. There are a ton of stats that each player has for each season so I’ve created a season model that has a player field as a foreignkey. So far so good, I’m struggling to get the data from the API in bulk but that’s another post.

So, we have player and career stats. Now, the next thing I need is team. Teams have all the location and historical stats but then they have players - I think players should reference team as a foreignkey with related name but then I’m not sure how I deal with players when they change team, should there be a former players field and a method to change team that would populate that?

Then we have schedule and match stats. Each game has two teams with a given roster and a given box score that’s not too bad. I need to be more confident in my data collection processes before I’d trust it live.

That’s the main functionality so far. Typing this has helped me clarify my thinking a bit - I’ll stick my work so far up on GitHub at some point if anyone is interested.

If you have initial thoughts, similar projects that might be inspiring and helpful I’d love to hear it.

Hope you’re all doing well!

/r/django
https://redd.it/7gohks
I am after a link to a video of Raymond Hettingers' ...

I lost my bookmarkto a video of Raymond Hettinger's where he discusses best practices when wrapping an external library written in some other language to make it Pythonic. It discusses things like conforming to the Python iterator protocol when the orginal library has just a `get next` function that ends by returning a sentinel value; and other such Pythonicisms.

Your help is appreciated, Thanks :-)


/r/Python
https://redd.it/7gqdni