Django вывод данных после запроса как нет - PullRequest
0 голосов
/ 06 марта 2020

Я пытаюсь получить значение bally и ballx для вывода с моим почтовым запросом (без использования каких-либо форм в качестве требования проекта), мне удалось получить почтовые запросы без использования формы, однако информация out ставит как ничто, bally: None ballx: None, я чувствую, что я совсем близко, совсем новичок в python. Куда я иду не так

вот шаблон / индекс views.py

from django.shortcuts import render
from django.http import HttpResponse
from django.http import JsonResponse
from pong.models import SimpleBot

def home(request, template='index.html'):
    axis = HttpResponse(play(request))
    return render(request, template, {})


def bot(request):
    ballx = request.GET.get('ballx')
    bally = request.GET.get('bally')
    paddley = request.GET.get('paddley')
    court = {'ballx': ballx, 'bally': bally, 'paddley': paddley}
    data = {
      'up': SimpleBot.simple_bot(court),
    }
    return JsonResponse(data)

def play(request):
    ballx = request.POST.get('ballx')
    bally = request.POST.get('bally')
    court = {'ballx ': ballx, 'bally ': bally }
    print(court)
    return HttpResponse(court)

. html

{% load static from static %}
<!DOCTYPE html>
  <head>
    <title>Pong</title>
  </head>
  <h1>Pong<h1>
  <body>
   <canvas id='pong' width='600' height='400'></canvas>
   <script src={% static "pong.js" %}></script>
  </body>
</html>
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('pong/', include('pong.urls')),
    path('', include('pong.urls')),
]

Редактировать - теперь можно отобразить жестко закодированные значения после пары изменений теперь пытаются получить ballx и bally для отображения models.py

from django.db import models

class SimpleBot(models.Model):

    @classmethod
    def simple_bot(request, court):
        return court["bally"] > court["paddley"]

    @classmethod
    def post_bot(request, court):
        return court['ballx']

new views.py


def play(request):
    ballx = request.POST.get('ballx')
    bally = request.POST.get('bally')
    court = {'ballx ': ballx, 'bally ': bally }
    print(court)
    data = {
      'ballx': SimpleBot.post_bot(court),
      'bally': 'hello'
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...