Printing Output from an External Python Script on Django Webpage

Viewed 147

I have incorporated an external python script into my Django webpage. I am currently able to display the output of my script in the terminal once a button is clicked, but I want my script to be displayed on my webpage once the button is clicked. The output I want displayed on the webpage from the script is stored in the variable 'res'.

This is what I currently have in each file relating to this issue:

Views.py

def reccomendation_system(request):
 #external python script for a recommendation system code•
 return res

class IndexPageView(TemplateView):
    template_name = 'main/index.html'

class ChangeLanguageView(TemplateView):
    template_name = 'main/change_language.html'

class MovieReccomdationView(TemplateView):
    template_name = 'main/recomend.html'

def results(request, res):
    return HttpResponse("Your personalised output:" % res)

urls.py

    path('reccomendation_system/', views.reccomendation_system,name='script'),
    path('results/', views.results, name='results'),

recomend.py

          <form action="/results">
        <button onclick="location.href='{% url 'results' %}'">Output on Webpage</button>
        {% if data %}
            {{data | safe}}
        {% endif %}
        </form>

The error that I am currently getting is:

TypeError: results() missing 1 required positional argument: 'res'

I am pretty new to Django so I'm not too sure where I am going wrong. The above code is what I seem to have gathered from different tutorials. Any help is appreciated :) thanks

0 Answers
Related