Abhijit Roy
Abhijit Roy

Reputation: 39

Django : How to import a python module such as pytube into a static template/webpage?

I am very new to Django. Recently I was developing a site just for getting aquainted with the framework and I came to a point where I needed to import a python module such as request,pytube etc into a static webpage so that i can use their functions . So two questions arose - 1. Is it possible to have python code embedded in static content. 2. How can I import a python module into a static webpage.

Upvotes: 0

Views: 656

Answers (1)

nerdenator
nerdenator

Reputation: 1297

Python code cannot be executed by the browser within the page. If you wish to execute code within the browser you will need to use JavaScript, which would be a completely different process. If you wish to manipulate values from a webpage using Django and other Python libraries, you will need to set up a form, take the input, wash it through a views.py file with the classes or functions you need, and then return those values as context variables that are rendered through template tags in your static page upon load.

If you are new to Django, I would highly recommend looking through the Django Project's main tutorial, found here.

Upvotes: 3

Related Questions