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
Problems Loading Image

I'm following a tutorial and attempting to create a blog in Flask, trying to return a default image for users when they create their profile. Flask can't seem to find the image I need, even though the path to the file seems correct. It returns a 404 error, saying the file can't be found:

​

"GET /static/profile\_pics/default.jpeg HTTP/1.1" 404 -"

​

Yet that is the correct path, the path to the image is:

​

"PycharmProjects/flaskwebsite1/flaskblog/static/profile\_pics/default.jpeg"

​

It finds the css style sheet, also in "static" correctly, so I'm really not sure what the issue could be as to why it isn't finding the image.

​

Here are the relevant code snippets. Here's the route that uses the image:

@app.route("/account")
@login_required
def account():
#need to add an image file for the user
#image files to be stored in static directory
form = UpdateAccountForm()
image_file = url_for('static', filename='profile_pics/' + current_user.image_file)
return render_template('account.html', title='Account', image_file=image_file, form=form)

​

Image\_file references the user class in my [models.py](https://models.py) file:


class User(db.Model, UserMixin):


/r/flask
https://redd.it/9g4r1f
How to access an authenticated user object in forms.py

In: `forms.py`

`from .models import User, User_asset_period_setting`

class UserAssetForm(forms.Form):
#need to filter by current logged in authenticated user
user_asset_choice = forms.ModelMultipleChoiceField(
queryset=User_asset_period_s etting.objects.all().order_by('asset_id')).filter(User.???#I want to access current logged in user id here)


I've tried making the request available in \`forms.py\` to no avail yet. The obvious solution is to just make a custom form in html, but I'd like to use Django's forms functionality if possible!

I refuse to believe there isn't away to do this!

/r/django
https://redd.it/opxtqf
Using multiprocessing with a generator function

I'm implementing some flask video streaming routes and the method which deals with the processing of frames is quite heavy hence I wanted to fork a child process that does this job and has to be synchronous. Using pipes and queues in the multiprocessing module in Python has to do with the return values and I couldn't find how do I use these with generator functions.

This is the minimal code :

def generateframe(): #need to parallelize this
frame = get
processedframe()
yield(b"--frame\r\n" b"Content-Type: image/jpeg\r\n\r\n" + bytearray(frame) + b"\r\n")

@app.route('/stream')
def stream():
return Response(
generate
frame , mimetype="multipart/x-mixed-replace; boundary=frame"
)

Can anyone please give some insights on how do I parallelize this?

/r/flask
https://redd.it/q7tc1m