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
Nonetype error in filepath = os.path.join(app.config'UPLOAD_FOLDER', filename)

I am making an app with Flask and this is my app.py code

from flask import Flask, rendertemplate, request, redirect, urlfor
from werkzeug.utils import securefilename
from background
subtractor import BackgroundSubtractor
import cv2
import webbrowser
import numpy as np
import base64
import os

app = Flask(name)

# Set up the upload folder
UPLOADFOLDER = 'uploads'
app.config['UPLOAD
FOLDER'] = os.path.join(os.path.dirname(os.path.abspath(file)), UPLOADFOLDER)

# Set up the static folder
STATIC
FOLDER = 'static'
app.config'STATIC_FOLDER' = os.path.join(os.path.dirname(os.path.abspath(file)), STATICFOLDER)



@app.route('/')
def index():
return render
template('index.html')

@app.route('/upload', methods='GET', 'POST')

def upload():
if request.method == 'POST':
if

/r/flask
https://redd.it/13h26r6
Flask Error message

Hi everyone , I have a project to create a website and link it to my trained classification model (Vgg16)

so I started to use Flask and I created two files:

the first one

from flask import Flask, render_template, request

from tensorflow.keras.models import load_model

from tensorflow.keras.preprocessing import image

import numpy as np

app = Flask(__name__)

model = load_model('modelV2_VGG16_8to2_ep20.h5') # load your trained model here

u/app.route('/', methods=['GET', 'POST'\])

def index():

result = None # initialize the result variable

if request.method == 'POST':

file = request.files['image'\] # get the uploaded file

img = image.load_img(file, target_size=(224, 224)) # load the image

img = image.img_to_array(img) # convert to array

img = np.expand_dims(img, axis=0) # add batch dimension

img = img/255.0 # normalize pixel values

​

prediction = model.predict(img) # make the prediction

result = np.argmax(prediction) # get the index of the predicted class

return render_template('mytemplates/index.html', result=result)

if __name__ == '__main__':

print(app.template_folder)

app.run(debug=True)

​

and the second one is
<!DOCTYPE html>

<html>

<head>

<title>Image Classification</title>

</head>

<body>

<h1>Image Classification</h1>

{% if result %}

<p>The predicted class is {{ result }}</p>

{% else %}

<form method="POST" enctype="multipart/form-data">

<input type="file" name="image">

<input type="submit" value="Upload">

</form>

{% endif %}

</body>

</html>

&#x200B;

However, after I run the flask run on command,I got this message "Internal Server Error The server encountered an internal error and was unable to complete your request.

/r/flask
https://redd.it/13gl5t5
{if request.user.is_authenticated} not work on html

I have a weird issue. For some reason `{if request.user.is_authenticated}` not work on navbar on index.html, but it work on other html pages. It always just shows Home and Login. Any help will be greatly appreciated. Thank you.

<nav>
<div class="brand-name">
<a href="/">BrandName</a>
</div>
<ul>
<li>
<a href="{% url 'articles:home' %}">Home</a>
</li>
{% if request.user.is_authenticated %}
<li>
<a href="{% url 'articles:article-create' %}">Create article</a>
</li>


/r/djangolearning
https://redd.it/13gmsgb
Sunday Daily Thread: What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.

/r/Python
https://redd.it/13gwu0m
Which Docker tutorial to use?

I've been trying to deploy my Django app for a while, and because I don't have any experience with docker and trying to deploy ASAP, I tried to follow tutorials and here's what I found:

reddit post \- This reddit post linked an article, which isn't that old, plus is using exactly what I need: Django (DRF in my case), Redis, Celery and Postgres. But it's saying that

>server and worker share the same Dockerfile

So that means that I'm hosting both Celery and Django on the same server. It's not a big problem, but I've already hosted celery on Railway and Django on Render, they work fine, the problem is that the article is not showing the deployment process and is using NGINX. Do I deploy the same way I do usually on Render or do I have to follow the article and eventually encounter problems with deployment?

youtube video \- Many people say good stuff about this one, but I think it's outdated. It was released in 2020 (correct me if I'm wrong).

and this youtube video \- He's also explaining the same things simply, but I'd say the same thing about it. Outdated???

/r/django
https://redd.it/13hb9i4
Guide for a complete beginner - Tips, tricks and tutorials

Hi everyone, I’m fresh out of CS50 and looking to expand in BE and DevOps. Is there any good course or tutorial that can help me to build from ground up, already know some Python, C and JS.

Would love the help!

/r/django
https://redd.it/13hi1rc
Trouble Deploying Django to Railway.app

I am trying to get Railway to work as I like their features. I had the Railway account for a few days before I realized that I could get to learn it way quicker if I upgraded my account to the Developer one. My intention is to deploy the Django project's development environment (app plus database) onto Railway. My Django project is API only and I need the frontend dev environment (which I will host in a separate environment on Railway) to have access to the backend's API endpoints online.

When I deploy the development environment now, after referencing https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Deployment#getting\_your\_website\_ready\_to\_publish, I get the following deploy log "Watching for file changes with StatReloader

"Performing system checks... System check identified no issues (0 silenced). May 14, 2023 - 16:19:46 Django version 4.2.1, using settings 'project.settings.local' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C."

However, I get "Application failed to respond" when I try to access the project using the generated domain.

Here are the rest of my configurations and logs: build log: https://pastebin.com/pKw65eGe (I hid some data by replacing it with "xxx") base.py (base settings) https://pastebin.com/5fTkXTGB local.py (dev environment) https://pastebin.com/cfLPiDzm requirements.txt https://pastebin.com/T35yEriz (I'll clean it up once I figure out which libraries I do

/r/django
https://redd.it/13hj7bl
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/13hrkfo
Using NextJS for templates a sensible choice?

Hey! I have a personal project I’ve been working on for over a year as a solo dev. I am experienced with Python, and have been using Django for my project. It has an API for mobile, and I am building a dashboard.

I gave templates/htmx/alpine a try, and found limitations pretty fast. These could be due to my inexperience with these, but I find making reusable components (how one would in say, react) to be difficult. And trying to have an edit form modal that shows a toast afterwards seemed like it was a lot to figure out with htmx/alpine (I was able to get them individually, but not both in order).

I work professionally with Vue, but all the component libraries for React seem great and make developing beautiful UIs and reusable components quite easy. I could be wrong, but I think doing a UI with something like Mantine could be a similar amount of work as Django templates - but far more flexible and easy to get nice results.

The benefits that NextJS provides seem really interesting, but the one thing I wonder about is if it is a bad approach to have Django being a service that next

/r/django
https://redd.it/13hu98j
Any must-have extensions for working with Python in VSCode/VSCodium?

Suggestions for extensions that help in general and not just with Python, are also welcome.

/r/Python
https://redd.it/13h2xuc
Multiparadigmatic Web Scraping Tool!

Hello! Hope you're all doing fine! I recently developed a multiparadigmatic web scraping tool with web crawling included as you can define the max hops it takes inside every link it finds inside a webpage!

It uses Async/IO to give maximum performance! Wanted to use multithreading to boost the HTML Parsing part since it's more of a CPU Bound part, but I benchmarked using multiprocessing and the overhead of creating multiple processes just for parsing wasn't worth it, since I'm quite experienced with C I might create a simple wrapper around this tool.

It's great to embed in a Browser Extension or just for any general purpose data mining on the web you might need. Instead of writing purpose specific scrapers for that particular web page you can just use this library.

Give me your sincere opinion since it is my first time publishing and authoring a python library, and it's my first OSS getting actually 16 stars. With this post I hope to get good insight and to learn and improve my python knowledge! My first programming language was C!
I know I got to automate the publishing process with GitHub Actions, the same way I have it for

/r/Python
https://redd.it/13hkrgc
Release 0.6.0 of FastKafka adds Redditors' requested features

FastKafka is a powerful and easy-to-use Python library for building asynchronous web services that interact with Kafka topics. Built on top of Pydantic, AIOKafka and AsyncAPI, FastKafka simplifies the process of writing producers and consumers for Kafka topics and automatically generates documentation for such microservices.


This release contains s number of feature requests from Redditors. Please take a look and let us know how we can make it better for you and your use cases.

https://github.com/airtai/fastkafka

/r/Python
https://redd.it/13i0eaz
A short bugfix story about UnicodeDecodeError: 'utf-8' codec can't decode byte

Hi everyone. Hope you are doing well.

I just wanted to share a short story with you about my yesterday's journey of bug fixing.

I am not a professional programmer but I have a working live webservice made on flask.

It appears, that when return render_template("about.html") happens, inside Flask there is some check happens whether passed html code has utf-8 symbols or not.

Error was: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position ... which was hard to debug because track trace was pointing out to my return render_template code and that was it. Position error was pointing to something inside a Flask files, not in my html. Other errors inside track trace were happening also inside Flask files.

What I normally do, when I update my code locally in PyCharm, I push it to private github and then just copy a text version of a file (code) to my production server via WinSCP, just via editing same file on server. I don't do a lot of changes so it is just easier for me, I guess.

So when I did slight change to my about.html on my local machine when everything worked fine, I copied code, opened remote SSH connection via WinSCP to

/r/flask
https://redd.it/13fe6rt
How do you maintain a development environment as well as a production version of your Django projects?

New to Web Dev and Django. I have created my first Django project and have deployed it to a website that I own. I am struggling to make a nice workflow to allow me to both develop and test my app, as well as deploy it when I am happy.

My current workflow is to write new code in the production version of my app which is currently deployed to my website. I write the code locally on VS Code, push to Gitlab, jump onto my server, and pull the latest code. This takes a while and isn't a nice way to develop and test quickly.

I can't seem to find any guidance online about managing and developing a running website. Does anyone have any suggestions on improving my workflow, and maintaining a separate space for development?

/r/django
https://redd.it/13i9h19
A Python package to retrieve data from Steam

Hi guys, I recently just build this lightweight package called steamcrawl after seeing that people are having trouble accessing/querying certain information on Steam. It simply makes a query to Steam, sorts the important information from the messy JSON then returns a pandas DataFrame. Here are some features that my package has been able to do so far:

\- Get your listing/buying/selling/cancelling on the community market.
\- Get all app id
\- Get the price history of an item.
\- Get the item id of an item.
\- Get buy/sell orders of an item.
...and more.

If you are interested, please give it a visit at: https://github.com/Hungreeee/steamcrawl
Note: the code is completely open, you can freely look into it or take it for personal use, I really don't mind that. I think it can be useful for educational purposes, especially for anyone who is trying to crawl Steam data but just doesn't know where to start.

/r/Python
https://redd.it/13i7oyy
I interviewed Joris Schellekens, author of the Borb PDF library, about his progress on building a business around an open source library. “If you want a library that is regularly updated by a team of developers, someone needs to pay those developers.”
https://codecodeship.com/blog/2023-05-15-joris-schellekens?utm_source=reddit

/r/Python
https://redd.it/13i6wo4