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
Effizient way to let a Django/flask app communicate with a ESP8266 Board?

At the moment I have only 2 ESP Boards that I would like to control via Web, and if this goes well, some more in the future. These Boards are supposed to control some lights and a couple of relays. I would like to control them via web, but with one central application.

The first thing that came in mind, is either a Flask or Django application.

But how would I achieve the communication between the web application and Boards? My general idea is that the Boards are the clients, only listening to commands and the web app is sending the instructions.

/r/Python
https://redd.it/10ipt6v
Neat little program I made finally finished in the latest Pyt

I'm just getting back into things, and it's been a long time. I finally upgraded to 3.11 from 2.5 because it's been so long. I'm basically back to newbie. I was getting good in 2.5 and didn't want to upgrade then. Anyways, here's a program I just fixed I made yrs ago. I figured it might help some just getting started. Enjoy!

​

# What are your Astrological Signs w/table - Michael Davis - January, 2011

print (" What Is Your " """"Western" """"And " """"Chinese" """"Zodiac Birth Signs!")
print ("")
print ("")
start = input(" Press " """"Enter" """"To Find Your Birth Signs!")
while not (start == ""):
print ("")
tryAgain = input("Are you sure you want to quit? Press Y to quit or N to

/r/Python
https://redd.it/10idyym
What should you do in order to be not indexed by Google, and other search engines?

Dear Flask developers,

I just don't want my website to be indexed by Google and other search engines. Every Blueprints' base.html file, has the code below as the head section.

{% block head %}
...
<meta name=”robots” content=”noindex,nofollow”>
...
{% endblock %}

\-Is it enough?

\-If it is not enough, could you please list the other necessary actions in other to be not indexed by search engines?

\-Do I need to tamper the WSGI file?

/r/flask
https://redd.it/10iqat8
Monday Daily Thread: Project ideas!

Comment any project ideas beginner or advanced in this thread for others to give a try! If you complete one make sure to reply to the comment with how you found it and attach some source code! If you're looking for project ideas, you might be interested in checking out Al Sweigart's, "The Big Book of Small Python Projects" which provides a list of projects and the code to make them work.

/r/Python
https://redd.it/10iydbm
Old-School Adventure Game with PyGame (love letter to Shadowgate)

For years, I've been wanting to put together and old-school PC adventure game (like Shadowgate or Maniac Mansion). I've never really had the time to sit down and put everything together (mostly, its just too time consuming to paint or draw all the game assets).

However, I recently discovered Midjourney as a quick way to generate assets. And, combined with PyGame "under the hood"; I am pretty impressed with how things are shaping up.

Everything in these screenshots (except the text) was generated for me in a couple of minutes with Midjourney (with a bit of post-processing on my end).

My game only has a few rooms at the moment, but, I've got the hang of things now and it should be fairly easy to see this to completion.

https://i.redd.it/w8ep1gq32oda1.gif

&#x200B;

&#x200B;

https://i.redd.it/w9dsgyj42oda1.gif

Feel free to hit me up with any questions if you’re interested in creating something like this (pretty niche group of people, I know :) )

/r/Python
https://redd.it/10ivej4
How to deploy a Flask, react (mysql) app ?

Hello everyone.
I've developed some apps, but never really deployed one. I've developed this app using flask, react and mysql.
what is the easiest way to deploy the app on a server.

/r/flask
https://redd.it/10ihdza
How to write a simple password changer?

Hi,

can you please explain how to create a password changer? After providing first password to the user, user should be able to change their fist password with their preference. So I created the code below. Could you please provide the necessary part?

@app.route("/changepassword",methods=['GET','POST'])
@loginrequired
def userchangepassword():
form=ChangePasswordForm()
if form.validateonsubmit():
#They should enter their first password
#New password
#New password again
return rendertemplate('/passwordchange.html',form=form)


EDIT: Please check my new comment below. I updated the code.

/r/flask
https://redd.it/10isg81
Running a Function In a Template (beginner Question)

So I am building a front end for a LinkedIn web scraper and I am trying to get the function to run inside my template.

The function scrape from my Liscript.py file takes in two arguments (keywords and skills) and prints a table based on the results.

I am able to take in 'keywords' and 'skills' variables and reprint them in my html template but what I would like to do is import the scrape function and run it in my argsconfirmed.html template but I always get an error that says scrape is undefined. I'm also not sure if I should be running it in my .py file or my html template.

Thanks

&#x200B;

app.py file:

u/app.route('/argscomfirmed', methods=["GET", "POST"\])
def argsconfirmed():
from Liscript import scrape
    skills = request.args.get('skills')
    keywords = request.args.get('keywords')


return render_template('argsconfirmed.html',skills = skills, keywords = keywords)



argsconfirmed.html:

{% extends "LIfront.html" %}
{% block content %}
<h4> These are the keywords you chose are:</h4>
<h4> {{keywords}}</h4>
<h4> These are the skills you chose are:</h4>
<h4> {{skills}}</h4>
<h4>Data:</h4>
<h4> {{ scrape(keywords,skills) }}</h4>


{% endblock %}

/r/flask
https://redd.it/10imf85
Jinja undefined error

Hello again reddit. Once again i am requesting your assistance.

I am using flask to follow along a youtube tutorial to create my first website. The video i am watching is [https://www.youtube.com/watch?v=dam0GPOAvVI&t=407s&ab\_channel=TechWithTim](https://www.youtube.com/watch?v=dam0GPOAvVI&t=407s&ab_channel=TechWithTim)

I have got to 37:00 min in successful however when I launch the server I do not get the navbar like in the video. I instead get this error.



# UndefinedError

jinja2.exceptions.UndefinedError: 'user' is undefined

## Traceback (most recent call last)

* File "C:\\Users\\keyes\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\flask\\app.py", line *2548*, in \_\_call\_\_
return self.wsgi\_app(environ, start\_response)
* File "C:\\Users\\keyes\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\flask\\app.py", line *2528*, in wsgi\_app
response = self.handle\_exception(e)
* File "C:\\Users\\keyes\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\flask\\app.py", line *2525*, in wsgi\_app
response = self.full\_dispatch\_request()
* File "C:\\Users\\keyes\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\flask\\app.py", line *1822*, in full\_dispatch\_request
rv = self.handle\_user\_exception(e)
* File "C:\\Users\\keyes\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\flask\\app.py", line *1820*, in full\_dispatch\_request
rv = self.dispatch\_request()
* File "C:\\Users\\keyes\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\flask\\app.py", line *1796*, in dispatch\_request
return self.ensure\_sync(self.view\_functions\[rule.endpoint\])(\*\*view\_args)
* File "c:\\Users\\keyes\\Desktop\\Flask\\web\\views.py", line *7*, in home
return render\_template("home.html")
* File "C:\\Users\\keyes\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\flask\\templating.py", line *147*, in render\_template
return \_render(app, template, context)
* File "C:\\Users\\keyes\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\flask\\templating.py", line *130*, in \_render
rv = template.render(context)
* File "C:\\Users\\keyes\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\jinja2\\environment.py", line *1301*, in render
self.environment.handle\_exception()
* File "C:\\Users\\keyes\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\jinja2\\environment.py", line *936*, in handle\_exception
raise rewrite\_traceback\_stack(source=source)
* File "c:\\Users\\keyes\\Desktop\\Flask\\web\\templates\\home.html", line *1*, in top-level template code
{% extends "base.html" %}
* File "c:\\Users\\keyes\\Desktop\\Flask\\web\\templates\\base.html", line *34*, in top-level template code
\>

/r/flask
https://redd.it/10ikb4h
How To Make Flask Apps The CORRECT Way

How's it going people? I've made a little crash course for "how to make flask apps." This tutorial is based on ironing out all the bs, issues, errors, and wrong directions tutorials make whilst trying to teach how to make flask apps. I'm not condemning them, but I want to show beginners how to make good flask apps without running into issues.

Repo link: https://github.com/Wizock/SuperiorPattern

# Video link: How To Make Flask Apps The CORRECT Way | The Superior Pattern

Please provide any feedback, I want this pattern to be as polished as possible so newcomers don't lose interest in web development because of stupid venv issues or circular import issues working with sqlalchemy db variable import issues.

/r/flask
https://redd.it/10j30ka
Is flask-talisman still the way to go?

I'm getting close to publishing an app and am curious if people are still using flask-talisman or if there's something better I should be aware of?

It looks like it hasn't been updates since 2019 so maybe it's outdated?

Chime in if you've used it and or have other suggestions.

Thanks flask community!

/r/flask
https://redd.it/10hx2fa
Need guidance on a custom security manager.

I am running into some issues with my deployment. I'll give you some background before I explain what I'm trying to do and what I need guidance on.

I have a Flask/AppBuilder app running in a container. This runs fine and works as expected. I want to run it on AWS Lambda behind an API Gateway. So, instead of making a ton of changes to my code (I would still like to run the container in it's current form in a different environment) I am making use of the lambda-web-adapter. This essentially adds a lambda layer which forwards requests that come in to your application. It actually works, kinda. The issue I have is when servicing a request. The way the web adapter works is it boots the app up when initially deploying the function. Then all subsequent invocations are serviced by the already started app.

The problem I have is with the custom security manager I wrote. This looks for a specific header in the request, but the header isn't there. This is probably due to the mapping between API Gateway and the web adapter. Problem is, the authentication header is not present either. This is weird, since when I use

/r/flask
https://redd.it/10i487y
I am trying to get an search query from elasticsearch working. I am sorry for making a duplicate post.

I even tried adding flash message and flashing posts_db and post. But I don't get any output.

&#x200B;

Here is the approx output I want. Or at the very least I want the post title and post body.

https://imgur.com/a/QyQMnhz

&#x200B;

Notice how I am not getting any info from the Post table.

&#x200B;

https://imgur.com/a/RSP3doJ

&#x200B;

Can someone help fix this?

&#x200B;

Here is the code I am using.

https://www.reddit.com/r/flask/comments/10d1zgg/i\_created\_some\_code\_to\_test\_the\_search/

/r/flask
https://redd.it/10i7216
If you have created an app with encrypted data and/or HIPAA compliance considerations, what packages and resources did you use?



/r/django
https://redd.it/10iwanc
What is your development cycle when using docker and containers? What's the general flow between developing locally and running the containers to test.

I'm new to docker and I've done plenty with Django for internal tools within the company. However, I figured I wanted to take a shot at docker as I'm playing around with an application that could potentially go onto a cloud service.

However, what is your development cycle using docker? I guess I'm a bit hung up how you manage development locally or not, the migrations, etc.

So far, the idea I've come to is store my .env arguments in there to run in debug mode, and then use SQL lite. Then on the flip side, the container to run with debug mode off and postgres.

Just trying to get thoughts, ideas, and best practices from the community.

/r/django
https://redd.it/10ivw8t
Is Djongo no longer being developed?

I have seen some people say that it is, when I looked at the repo the last update was 7 months ago.

I'm looking to develop an application that uses a rest back end and I just want to know before I develop

It's not a typo I am talking about the library Djongo not Django

Update: So you have talked me out of it

/r/django
https://redd.it/10ijs3s