Reputation: 145
I have this code on my views.py
import string, random
def draegg_view(size=40, chars=string.ascii_letters + string.digits + string.punctuation):
return ''.join(random.choice(chars) for _ in range(size))
My question is how could I print the random string generated since this code?, I can execute this code on python console but i wanna see the result on a page!!
Thanks.
Upvotes: 2
Views: 142
Reputation: 474003
Since this is a django view you are talking about, you need to return an HttpResponse
object.
In the simplest case, it would be:
import random
import string
from django.http import HttpResponse
def draegg_view(request):
size = 40
chars = string.ascii_letters + string.digits + string.punctuation
result = ''.join(random.choice(chars) for _ in range(size))
return HttpResponse(result)
Note that a view is one of the key components/concepts in Django, make sure you study Writing Views documentation section and the tutorial carefully.
Upvotes: 5
Reputation: 114038
import flask
app = flask.Flask()
@app.route("/")
def dreaegg_view(size=40...):
return ...
app.run()
is probably the easiest way to get it displayed in an html page ...
Upvotes: 4