django表单{{from.as_p}}未呈现任何文本框或输入

时间:2019-02-27 07:18:17

标签: django django-models django-forms

很抱歉,我想问一些简单的问题,但我只是想在我的Django项目中添加表单

我只是按照以下表格学习本教程: https://www.youtube.com/watch?v=6oOHlcHkX2U&t=115s

这是我的HTML表单

    <div class="form-popup" id="myForm">
      <form class="form-container" method="post">{% csrf_token %}
            {{ form.as_p }}
          <input type="submit" value="add">
        <button type="button" class="btn cancel" onclick="closeForm()">Close</button>
      </form>
    </div>

这是我在forms.py中的代码:

from django import forms
from .models import Stream

class CameraForm(forms.ModelForm):
    class Meta:
        model = Stream
        fields = (
            'name',
            'RTSP',
        )

我的views.py

from django.shortcuts import render, get_object_or_404
from CGI.models import tank_system, ambient, Limit
from CGI.basicfun import selectDates, weekSelect
import logging
logger = logging.getLogger(__name__)
from .forms import CameraForm

def index(request):
    forms = CameraForm(request.POST or None)
    if  forms.is_valid():
        forms.save()

    tank = tank_system.objects.latest('datetime')
    room = ambient.objects.latest('datetime')
    limit, created = (Limit.objects.get_or_create())
    return render(request, 'CGI/Pages/DashBoard.html', {'tank':tank,'room':room, 'limit':limit, 'form':forms})

这里是我的模特:

from django.db import models
from django.utils import timezone

class tank_system(models.Model):
... #my tank tables

class ambient (models.Model):
... #my room tables

class Limit (models.Model):
... #my limit tables

# here the class that use in the forms
class Stream (models.Model):
    name = models.CharField(max_length=30)
    RTSP = models.CharField(max_length=200)

我的应用网址

urlpatterns = [
    path(r'',login_required(views.index), name='index'),
    path(r'^Water-data-chart/',login_required(views.Lquid), name='tank'),
    path(r'^Ambient-data-chart/',login_required(views.Ambient), name='room'),
    path(r'Rest-api/', include(router.urls))
    ]

我的项目URL

urlpatterns = [
    path(r'admin/', admin.site.urls),
    path(r'accounts/', include('django.contrib.auth.urls')),
    path(r'api-auth/', include('rest_framework.urls'), name='rest_framework'),
    path(r'', include('CGI.urls')),
]

现在的问题是{{from.as_p}}应该创建一个html文本框,由我输入并发布其中的数据,

(这里的外观如何:)

What i'm support to see, picture taken form CFE

但是当我打开本地测试时,我什么也没看到

这是我看到的:

![what I'm see newly updated

让我感到困惑和困惑。

如果您能提供帮助,我非常感谢。

0 个答案:

没有答案