简体   繁体   English

在 view.py 之外使用 Django

[英]Using Django outside of view.py

I have a twisted based script running that is managing IO, monitoring serial inputs, writing logs etc. It uses Twisted to run events every minute and every hour as well as interrupt on serial traffic.我有一个基于 Twisted 的脚本正在运行,用于管理 IO、监控串行输入、写入日志等。它使用 Twisted 每分钟和每小时运行一次事件以及中断串行流量。

Can Django be used to provide an interface for this, for example taking live values and display them using Django 可以用于为此提供一个接口,例如获取实时值并使用

#python code generating value1 and value2

def displayValues(request):

  context = {
      'value1':value1,
      'value2':value2
  }

  return render(request, 'interface.html', context)

The obvious issue is that this python file doesn't live in the Django file setup and so the URL call wouldn't know where to look or how to call the displayValues function.明显的问题是这个 python 文件不在 Django 文件设置中,因此 URL 调用不知道在哪里查找或如何调用 displayValues 函数。

An additional feature I might look to is to write the IO values in to a mysql database through Django as it is already setup.我可能会考虑的另一个功能是通过 Django 将 IO 值写入 mysql 数据库,因为它已经设置好了。

I understand Django from a simple databases application point of view but this is not something I've come across online and I might be moving outside of the scope of Django.我从一个简单的数据库应用程序的角度理解 Django,但这不是我在网上遇到的东西,我可能已经超出了 Django 的范围。

I've seen this but it is more to do with using the Model outside of the standard setup.我已经看到了这一点,但这更多地与在标准设置之外使用模型有关。 Using Django database layer outside of Django? 在 Django 之外使用 Django 数据库层?

Is this possible?这可能吗?

Thanks!谢谢!

Why do you need Django for such a simple use case?为什么你需要 Django 来实现这样一个简单的用例? For simple Http requests you can you the included Python tool:对于简单的 Http 请求,您可以使用包含的 Python 工具:

https://docs.python.org/2/library/simplehttpserver.html https://docs.python.org/2/library/simplehttpserver.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM