我有以下意见:
class MiniView(generic.DetailView):
model = Automata
template_name = 'convert/mini.html'
context_object_name = 'automata'
command = "python MiniDFA.py"
subprocess.call(command, shell=True)
class DFAView(generic.DetailView):
model = Automata
template_name = 'convert/dfa.html'
context_object_name = 'automata'
command = "python NFAtoDFA.py"
subprocess.call(command, shell=True)
class TransitionCreate(UpdateView):
model = Automata
fields = []
[...]
command = "python make_graph.py"
subprocess.call(command, shell=True)
[...]因为我希望每次调用视图时都执行命令,但出于某种原因,似乎只有最后一个命令正常工作,我不知道为什么。剧本本身似乎运转良好。
我还注意到,每次服务器运行时,脚本都会执行,也不确定为什么。
发布于 2017-02-28 05:08:40
这些是类,而不是函数。如果您希望在每个请求中发生一些事情,则需要重写类中的一个相关函数。例如:
class MiniView(generic.DetailView):
...
def get(self, request):
...
command = "python make_graph.py"
subprocess.call(command, shell=True)
...
return HttpResponse(...)作为两个注意事项:
https://stackoverflow.com/questions/42500025
复制相似问题