检查 url 是否加载但实际上不加载 运行 app django 的自动方法?

automated way to check if url loads but not actually run app django?

我有一个编写 django 应用程序的 django 应用程序,这是我的主要投资组合演示。我调用了一个很酷的 API 来为您突出显示您的代码,但它 returns 有时会在 django 中爆炸,我不想几个月来解决这个问题。我确实想要一个脚本来一个一个地测试我所有的 urls,我已经有了 app_writer 写的,我想知道你如何在 django 中假装运行服务器,调用每个 url,和 return 响应 200 或在坏掉之前的什么 templates/links。有没有人这样做过,一般情况如何?在我看来,我必须使用 requests 编写一个外部脚本,并在这个运行时从不同的终端一个接一个地抓取它。这不是一个选项,因为它只是一个演示,我想在应用程序中进行。

谢谢

Django test client 可以发送请求并设计用于测试您的应用程序。这是一个简单的例子。

>>> from django.test import Client
>>> c = Client()
>>> response = c.post('/login/', {'username': 'john', 'password': 'smith'})
>>> response.status_code
200
>>> response = c.get('/customer/details/')
>>> response.content
'<!DOCTYPE html...'