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
Subdomain/path flask apps which can be individually restarted

Hi,

I'm working on Flask app which serves as a frontend for submitting jobs. Jobs are quite general here - of different kinds.


The API would look something like this:

* server.com/jobs_of_type_A/submit
* server.com/jobs_of_type_B/submit
* server.com/jobs_of_type_C/submit

after a submission, a job gets queued and it is eventually send for processing elsewhere. The types A, B, C, .. are rather different, and Flask apps serving them need to be configured differently. And, of course, there is more to it than just the submit endpoint.

What I'm wondering about is how to make this frontend very flexible. The server.com administrator should be able to create/restart/cancel different endpoints just like this on the command line:

* $ job_app --config=type_D.json --prefix=jobs_of_type_D create #creates a new endpoint and starts its processing machinery
* $ job_app --config=type_B2.json --prefix=jobs_of_type_B restart #restart the Flask part with a different configuration
* $ job_app --prefix=jobs_of_type_C delete #delete endpoint and teardown processing machinery

Will I be better off with a design which basically for *each* job type handles its own full processing line:

> nginx:portA --- gunicorn --- flask app(configA) --- reddis --- jobA_executor


Or is it better to approach it as:

> nginx --- gunicorn --- flask dispatcher --- flask app (configA) --- reddis ---

/r/flask
https://redd.it/esahm6
New Flask Library that makes uploading & saving files super easy!

​

https://preview.redd.it/e8wznjkxf9o41.jpg?width=2200&format=pjpg&auto=webp&s=d1fee8b83aabca388a00a454ef5e38284d264f40

Hi guys

I have just released v0.1.2 of a new Flask library to make uploading files and storing them on your server & database as easy as possible... just let Flask-File-Upload handle all the repetitive work!

Works with Flask & Flask-SQLAlchemy

[https://github.com/joegasewicz/Flask-File-Upload](https://github.com/joegasewicz/Flask-File-Upload)

The v0.1.2 release includes an option to clean up the whole directory, so you don't have lots of empty dirs on your server [https://github.com/joegasewicz/flask-file-upload#delete-files](https://github.com/joegasewicz/flask-file-upload#delete-files):

​

# If parent kwarg is set to True then the root primary directory & all its contents will be removed.
# The model will also get cleaned up by default unless set to `False`. blog_result = file_upload.delete_files(blog_result, parent=True, files=["my_video"])

If anyone has installed this library & wishes to use the above feature, please run:

pip install flask-file-upload --upgrade

I would be very grateful if anyone wishes to try out this library & or give some feed back & star! And of course contributions are more than welcome.

Thanks so much

​

Joe

/r/flask
https://redd.it/fn3ima
i want to Redirect to the same view after delete??

**so after deleting comment i can't back to detailviews of my comments , i need back with the pk of the post**

\#error

`Reverse for 'CommentsBack' not found. 'CommentsBack' is not a valid view function or pattern`



#views
# list all the comments of ever post l
class comment_back (DetailView):
model=Post
template_name='CommentsBack.html'

#delete comment by his primary key
def delete_comment(self,pk):
event=Comment.objects.get(pk=pk)
event.delete()  
return redirect('CommentBack')

​

#urls

path('mypost/<int:pk>/commentBack', comment_back.as_view(),name="commentBack"),
path('DeleteComment/<int:pk>/remove', views.delete_comment,name="delete_comment"),

/r/djangolearning
https://redd.it/uplkto
In flask I have a function that updates different columns in flask sqlalchemy but the columns won't update. Put simply the update doesn't have any effect on the code. What am I doing wrong?

        return redirect(url_for('auth.login'))
        return redirect(url_for('auth.login'))

# now is added because of pytest + now represents the current time
def reset_attempts_token_tried_to_0(user_db, now):
'''
if the max attempts of the token tried is exceeded + the
token is expired reset the attempts_token_tried to 0.
'''

# why doesn't work
time_token_expired_db = user_db.time_token_expired
# executes at 9:00 <= 9:30pm
current_time = now

#delete
flash(f'user_db.attempts_token_tried {user_db.attempts_token_tried}')
flash(f'current_time {current_time}')
flash(f'time_token_expired_db {time_token_expired_db}')



/r/flask
https://redd.it/1f14zga