Answer the question
In order to leave comments, you need to log in
How to interact with custom python code?
Hello. Google didn't give a specific answer to my question.
I have a parse.py that parses a website and sends information to MySql.
1) How can I run this file through a normal html button?
I found a temporary solution, I submit the form (using the POST method), in the view
# view.py
import parse
def parse_site(request):
if request.user.is_superuser: # Страница доступная только администратору
if request.method == 'POST':
parse.main() # Мой парсер
return render(request, 'parse.html')
Answer the question
In order to leave comments, you need to log in
1) How can I run this file through a normal html button?
How to display some information on the page (not the result of parsing, but intermediate, for example, the response code from sent requests), which comes from parse.pyThis will be a complication for the system, but it is quite possible. After all, the response statuses will be received very quickly and they will need to be stored in the database, and the client must periodically poll the statuses or receive them via SSE. And sometime you will have to clear the database from old results.
How to stop the parsing processThe handler that started the parsing should determine by periodic access to the database that the task has been cancelled.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question