我想通过onclick执行我的python代码.我在运行服务器后得到了结果.我的按钮不起作用.这是我的代码.
网址 -
url(r'^index/$', index),
Run Code Online (Sandbox Code Playgroud)
index.html-
<html>
<body>
<form action="/index/" method="GET">
<input type="submit" value="Click">
</form>
{{output}}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
views.py -
from django.shortcuts import render, render_to_response
from pythoncode import mycode
def index(request):
if request.method=="GET":
py_obj=mycode.test_code(10)
py_obj.code()
return render(request, 'index.html', {"output":py_obj.a})
Run Code Online (Sandbox Code Playgroud)
我创建了另一个应用程序来分隔python代码 - 应用程序名称是python代码和文件名mycode
class test_code:
def __init__(self, a):
self.a=a
self.b=4
def code(self):
return self.a, self.b
Run Code Online (Sandbox Code Playgroud)
请帮我.我是Django的新手.提前致谢