All,
I have just started learning python and django and I was wondering if there's a way to call a python script (Test.py) from a link on the django page. So far I have created a django project (TestDjango) and I have these files in that folder:
__init__.py
settings.py
urls.py
views.py
Test.py
This is what I have in my views.py script so far:
from django.http import HttpResponse
def index(request):
return HttpResponse('''<h1>Test</h1>
<p>
<!-- <a href = "https://www.python.org/"> Python </a> </br> -->
</p>
'''
and in my urls.py I am calling it this way:
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index, name ='index'),
]
When I run this on the server I get a simple page with title - "Test" and a clickable "Python" link which takes me to the python website. However, what I am looking for is a way to add a link on that django page which would call my "Test.py" script when you click on, say "Test". I have done some visualizations in that script with some mocked up data that I'd like to see on my webpage. It might be something very simple, but, I couldn't find a way to do it. Any guidance would be appreciated.
Please let me know if I missed something or any suggestion you have for me when I post any question next time.
indexview function. If your visualization code outputs an image, you can then return the image in theHTTPResponse.