PizzaPatz
PizzaPatz

Reputation: 58

Django: Is there a way to make client render Python 3 functions locally?

I have a project that I want a client to run a for/while loop on his/her machine. Is there a way to do such a thing since views are run on server-side, such as below:

views.py

from django.shortcuts import render

def index(request):
    for i in range(0,10000):
        # Do stuff
return render(request, 'app/index.html')

Javascript was one of the option for client side but I have some libraries that are from Python 3 I want to run.

Update: I'm building a Django app on Heroku that will implement proof-of-work function for blockchain. The concept of proof-of-work function requires a computation to be done by a client. What I want to accomplish is to have a template for a client to run their resources in Python using Crypto library (from Crypto.Hash import SHA). Here is the example repository I'm trying to follow blockchain-python-tutorial. The repository is run locally in Flask and not meant to be run on an actual server, since the repository is theoretical and not practical. So I was wondering if there's a way to build a replica of the app with Django on Heroku. Thank you.

Upvotes: 0

Views: 107

Answers (1)

Jon Hrovat
Jon Hrovat

Reputation: 595

Django does not support ranged for loops in the template. Aside from that, what you're attempting breaks the MVC rules of design. The solution you're looking for will be hard to implement because you're going against how Django is designed to work.

If you need more python functionality, you should learn about custom Django template tags. If there's a specific use case you need help with, please elaborate in your post.

Upvotes: 1

Related Questions