Я пытаюсь проверить, работает ли запрос get, но я не уверен, как это сделать в django. У меня есть база данных postgre, подключенная к серверу django, и я пытаюсь проверить, могу ли я заставить работать запрос GET, но яне могу найти ничего конкретного в интернете.
У меня есть некоторый опыт тестирования apis с помощью Flask, но не с Django.
views.py
from django.contrib.auth.views import login_required
from django.shortcuts import render
from django.http import HttpResponse
#from cameras.models import CameraQuerySet, Camera, CameraAuthenticationToken, CameraGroupQuerySet, CameraGroup, CameraStatusUpdate, CameraGroupLog
from . import models #if not up
@login_required
def camera_lookup(request):
serial_number = request.GET.get('serial_number')
found = 0
if serial_number != None:
serial_number = serial_number.lower()
found = Camera.objects.filter(serial_number=serial_number).count()
return HttpResponse(str(found), content_type="text/html", status=200)
urls.py
from . import views
from django.urls import path
app_name = 'cameras'
urlpatterns = [
path('add/', views.add, name='add'),
path(r'api/1.0/camera/', views.camera_lookup, name='camera_lookup'),
models.py
class Camera(TimeStampedModel):
public_identifier = models.UUIDField(unique=True,
default=uuid.uuid4,
editable=False)
serial_number = models.CharField(max_length=100,
unique=True,
null=True)
name = models.CharField(max_length=50, blank=True, null=True)
group = models.ForeignKey('CameraGroup',
on_delete=models.SET_NULL,
null=True,
related_name='cameras',
related_query_name='cameras')
group_tracker = FieldTracker(fields=('group',))
objects = CameraQuerySet.as_manager()
#identifier from assembly (what parts does the camera consist of)
bom = models.CharField(max_length=50, blank=True, null=True)
#what firmware is the camera on (mender artifact name)
firmware = models.CharField(max_length=50, blank=True, null=True)
#last seen at ip
last_sighting_ip = models.CharField(max_length=50, blank=True, null=True)
last_sighting_time = models.DateTimeField(null=True, blank=True)
#json blob that the camera can send home w. health status
health = models.TextField(blank=True)