mirror of
https://git.kotyczka.ch/developers/django.git
synced 2025-04-06 07:45:08 +02:00
38 lines
1.1 KiB
Python
Executable File
38 lines
1.1 KiB
Python
Executable File
from django.shortcuts import render
|
|
from django.http import HttpResponse, JsonResponse
|
|
from pyapp.models import ShoppingItem
|
|
from rest_framework import viewsets
|
|
from pyapp.serializers import ShoppingItemSerializer
|
|
|
|
class ShoppingItemViewSet(viewsets.ModelViewSet):
|
|
queryset = ShoppingItem.objects.all()
|
|
serializer_class = ShoppingItemSerializer
|
|
|
|
def index(response):
|
|
return HttpResponse("Welcome to PyApp")
|
|
|
|
def pyapp_home(request):
|
|
if request.method == 'POST':
|
|
print('Received Data',request.POST['itemName'])
|
|
ShoppingItem.objects.create(name= request.POST['itemName'])
|
|
all_items = ShoppingItem.objects.all()
|
|
return render(request,'pyapp.html',{'all_items': all_items})
|
|
|
|
def api_home(request,endpoint, params={"message": "Your JSON Repsonse"}):
|
|
body = request.body
|
|
data = {}
|
|
try:
|
|
data = json.loads(body)
|
|
except:
|
|
pass
|
|
print(request.GET)
|
|
print(data)
|
|
data['params'] = dict(request.GET)
|
|
data['headers'] = dict(request.headers)
|
|
data['content_type'] = request.content_type
|
|
return JsonResponse(data)
|
|
|
|
##return JsonResponse()
|
|
|
|
|