我正在使用django測試框架來測試我的API。我有一個簡單的視圖,在地址GET http://localhost:8000/v1/ping/
處返回「ok」。當我運行服務器並使用Chrome進行測試時,它運行良好。但是,當我對它啓動測試時,出現404錯誤。這是我的測試:Django測試返回404錯誤
def test_ping(self):
c = Client()
response = c.get('/v1/ping/')
print response.content
print response.status_code
和響應:
<h1>Not Found</h1><p>The requested URL /v1/ping/ was not found on this server.</p>
404
你如何測試以及如何運行服務器? – joeButler
我使用./manage.py runserver運行服務器,並使用./manage.py test進行測試 –
您不需要運行開發服務器來執行測試,其餘部分位於@ kreld的響應 – ElmoVanKielmo