I would like to write a script that is not activated by a certain URL, but by clicking on a link from the admin interface. How do I do this? Thanks!
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
But a link has to go to a URL, so I think what you mean is you want to have a view function that is only visible in the admin interface, and that view function runs a script?
If so, override
admin/base_site.htmltemplate with something this simple:This (should) put the link at the top of the admin interface.
Add your url with named pattern to your urls.py
Then just make a normal django view and at the top of the view check to make sure the user is superuser like this:
That will prevent unauthorized people from accessing this view.
Next, in your view after the above code, just run the script.
Do that with Python’s subprocess module, for example: