如何在Django中添加数学计算?

发布于 2025-02-10 23:25:44 字数 2245 浏览 1 评论 0原文

我完全感到困惑,如何在Django中添加数学计算以在我的页面上显示?我绝对不知道该如何处理。谢谢您的帮助:D

评论:

我熟悉Django,我已经在Django和Blask中为自己制作了一个应用程序,但是那是为了填写页面上的桌子并写入数据库,现在我想要制定一个运动飞机计算程序,我被卡住了。...我不知道如何使用数学和物理数据,

我需要有关如何执行此操作的实用技巧,而不是链接到Djang的教程,尽管我很感激对于那些也是如此:d

calculate.py

from random import randint
import time
t = time.time()

class Calc:

    def __init__(self):
        pass

    def position(self):

        self.positionX = []
        self.positionY = []

        self.positionX.append([(randint(1, 100) * x) for x in range(1, 2, 1)])
        self.positionY.append([(randint(1, 100) * y) for y in range(1, 2, 1)])

        return self.positionX, self.positionY


    def __str__(self):
        return {self.positionX, self.positionY}

if __name__ == '__main__':

        t = 0
        while t < 20:
            hear = Calc()
            print('X: ', hear.position()[0], 'Y: ', hear.position()[1])
            time.sleep(0.4)
            t += 1

型py

class CleanRobot(models.Model):
    """Robot Position and Speed Simulator"""
    name = models.IntegerField(choices=CHOOSE)
    velocity = models.FloatField(null=True, blank=True)
    positionX = models.FloatField(null=True, blank=True)
    positionY = models.FloatField(null=True, blank=True)
    angleTHETA = models.FloatField(null=True, blank=True)

    class Meta:
        verbose_name = "CleanRobot"
        verbose_name_plural = "CleanRobots"

def __str__(self):
    return self.name

views.py #@method_decorator(login_required,name ='dispatch') 类CleanRobotView(查看): ''...'''

    def get(self, request):
        return render(request, Calc())

forms.py

class Robo(forms.ModelForm):
    """New note add form"""

    class Meta:
        model = CleanRobot
        fields = '__all__'

html
{% block title %}Robot{% endblock %}

{% block content %}
    <form method="POST">
        {% csrf_token %}
        {{ positionX }}

{#        <input type="submit" class="btn btn-second btn-lg" value="Wyślij">#}
    </form>
    <button type="button" class="btn btn-primary btn-lg"><a href="{% url 'menu' %}">Powrót</a></button>
{% endblock %}

I am totally confused how to add math calculations in django to display on my page? I have absolutely no idea how to approach this. Thank you for your help :D

comment:

I am familiar with django, I have already made one app for myself in Django as well as in Flask, but that was to fill in tables on a page and write to a database, and now I want to make a program for sports plane calculations and I am stuck.... I don't know how to work with mathematical and physical data

I need practical tips on how to do this, not links to Djang's tutorial, although I am grateful for those too :D

calculate.py

from random import randint
import time
t = time.time()

class Calc:

    def __init__(self):
        pass

    def position(self):

        self.positionX = []
        self.positionY = []

        self.positionX.append([(randint(1, 100) * x) for x in range(1, 2, 1)])
        self.positionY.append([(randint(1, 100) * y) for y in range(1, 2, 1)])

        return self.positionX, self.positionY


    def __str__(self):
        return {self.positionX, self.positionY}

if __name__ == '__main__':

        t = 0
        while t < 20:
            hear = Calc()
            print('X: ', hear.position()[0], 'Y: ', hear.position()[1])
            time.sleep(0.4)
            t += 1

models.py

class CleanRobot(models.Model):
    """Robot Position and Speed Simulator"""
    name = models.IntegerField(choices=CHOOSE)
    velocity = models.FloatField(null=True, blank=True)
    positionX = models.FloatField(null=True, blank=True)
    positionY = models.FloatField(null=True, blank=True)
    angleTHETA = models.FloatField(null=True, blank=True)

    class Meta:
        verbose_name = "CleanRobot"
        verbose_name_plural = "CleanRobots"

def __str__(self):
    return self.name

views.py
# @method_decorator(login_required, name='dispatch')
class CleanRobotView(View):
'''... '''

    def get(self, request):
        return render(request, Calc())

forms.py

class Robo(forms.ModelForm):
    """New note add form"""

    class Meta:
        model = CleanRobot
        fields = '__all__'

html
{% block title %}Robot{% endblock %}

{% block content %}
    <form method="POST">
        {% csrf_token %}
        {{ positionX }}

{#        <input type="submit" class="btn btn-second btn-lg" value="Wyślij">#}
    </form>
    <button type="button" class="btn btn-primary btn-lg"><a href="{% url 'menu' %}">Powrót</a></button>
{% endblock %}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文