so I have a python script I'd like to integrate to work with python. No matter what I do I don't seem to get it right. Below are what I've managed to do successfully which is getting Django to accept picture upload and display them to the user.
https://replit.com/#Eddyah5/ImageConverterwithHTML#main.py
I'm now trying to get my python script in the link above to work in Django to let users upload pictures out of the list of supported formats, convert the picture to .ico of different sizes, and zip them for download by users. Please pardon me I'm very new to python/Django. What to do with the views.py, models.py as pertaining my code is in the link below?
https://replit.com/#Eddyah5/ImageConverterwithHTML#main.py
I'm very new to python and Django, so any help I will deeply appreciate.
If you want to do this from Django admin then look into Admin Actions: https://docs.djangoproject.com/en/4.0/ref/contrib/admin/actions/
If you want to do it from frontend then make an API and call you code from view.
Related
I want to be able to run my own python script (which will basically just print out the response with a bit of formatting) whenever a new response is submitted to my google form. I looked at google's python API for forms, but it doesn't seem to have a way to set up a trigger so that the script executes when a new response is submitted. Best it can do is pull a response ID after the fact and give me the details of the response. Is there a way to do this? From what I've seen google's apps script can't do what I need it to (print stuff onto paper), so I would prefer to make a trigger for my own python script.
Any help appreciated. If the answer to this question is painfully obvious, please guide me in a good general direction because I'm totally lost.
Thanks!
You have to rethink your "solution" as the Google Forms API doesn't support triggers but Google Apps Script script does, i.e., you might make your Python program to poll the form or the linked spreadsheet.
From https://developers.google.com/forms
Automate Google Forms with simple code
Anyone can use Apps Script to automate and enhance Google Docs in a web-based, low-code environment.
Automate tasks based on Google Form submissions.
So basically I am working on a project where the backend is made with python and the frontend is made with Angular.
So in that, all the backend processes generate logs in the log file. So, I need to create a program that shows the data of the log file at Angular frontend. Also, we need to show logs like that we see at the firebase, etc. with all kinds of important filters.
Currently, I don't have any idea, how to create such a program.
So, please anybody can help me to develop this kind of program.
I would like to make a web application where a user can:
click a button on a webpage to create a **random video (with moviepy)
play that video back on the webpage
click the button again to create a new **random video that replaces the existing one
** The random video will be created with a python/moviepy script that downloads a bunch of random video clips from the internet to a directory on my computer. It then compiles them into one video (.mp4 file).
I've done the python script bit already which successfully creates the video file.
To make the web app bit I have been recommended django and that's where I'm stuck!
So far I have installed django and got to grips with the basics .. I have a home page that says "Hello world".
My question is where do I go from here?
How do I connect my python/moviepy script with django?
What steps, apps, components etc, within django should I look into to make this thing?
I'm new to coding and looking for some guidance.
Thanks!
If you create a model with FileField then your moviepy script should upload videos into that field, that field can save the video in a specified directory in MEDIA_ROOT(you can store your post based on date) then that field will store the URL to it (you need to specify MEDIA_URL in settings.py). You can define some sort of IDs to them, if video privacy is not important, then you can use the model IDs. These IDs can be obtained trough Path converters .
At the client-side, javascript is needed. Simply running the script in view is possible, but then the user will need to wait for the response (and the browser should run into time-out).
You should look at server-sent events. With Vue.js you can easily display a loading element while waiting for the event (a video to be generated) and then download and switch to the video (see Django CRUD application tutorials). The python script can run asynchronously (you call it in the view).
It is a lot, I know.
Actually I'm going to learn these now, sorry for mistakes.
As I see, Django is for complex sites, you should look for Flask instead.
(I am learning Django and I know nothing about Flask, so I`ll go with it)
Here is the needed setup:
define the urlpatterns for handling the URLs
create a model for storing your video
create a django template for your page (html)
define a view for rendering out the template (passing the video)
maybe some css to design it
You can run your video generator(in the view) at every reload and override existing video(in this case you don't even need a model) or you can save the generated videos and capture the IDs in the URLs (for example: https://yoursite.com/1), in this case, the videos remain shareable.
If you go with the first option and sharing videos is not important for you then you could write a simple html page with a video and a button. The button can trigger a javascript function to run the video generator python script and refresh the page(the video is overridden), you may need to wait to the script otherwise the old video can load.
Restful API is a more advanced way to refresh the video, without reloading the page.
After these, you can deploy your page using an Apache server for example.
I tried to give you some guidelines (I am learning this on my own)
Hope that it helped :) There are tutorials for these.
I'm new to Django so don't be mad if this question might seem stupid.
I would like to add some functionality to my django web page. I need to add script that would send newest feed for subscribed users. Basically I would like to activate script when admin saves new post, but I don't know how modify admin page.
Maybe there is other solutions for this kind of task?
I am planning to build a simple web page that has an upload file option, submit button and a table to display the results.
The file i would be uploading is an XML file.
Upon submit, a python script should validate the XML file and display the discrepancies in the HTML page.
What is the best way to proceed with the front end and python integration? I have already validated the XML using python scripts but i am unable to find out a way to integrate it with HTML, upload & submit buttons.
Kindly help or let me know if you need any further details.
You'll want to use a web framework to do this. Some good options for python are Flask and Django. HTML is meant to run on the client's browser, where Python (in this situation) is meant to run off of a server. Django, Flask, and others make this quick and easy to do.