2017-10-26 11 views
-1

양식이 브라우저에 표시되지 않는 이유는 무엇입니까?장고 템플릿이 템플릿에 표시되지 않습니다.

index.html을

내 브라우저에서 테스트하고 검사 할 때, 나에게이 크기의 형태로 제공
<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <title>{{ structure.name }} - Details</title> 
    </head> 
    <body> 
    {% if error_message %} 
    <p><strong>{{ error_message }}</strong></p> 
    {% endif %} 

    <h3>Structure: {{ structure }}</h3> 

    <h3>Ajouter enregistrement</h3> 
    <form action="{% url 'Structure:addrecord' structure.id %}" method="post"> 
     {% csrf_token %} 
     {% for structure in all_structures %} 
     <input type="radio" id="record{{ forloop.counter }}" name="record" value="record.id"> 
     <label for="record{{ forloop.counter }}"> 
      Nom de l'enregistrement: {{ record.record_name }} 
     </label> 
     {% endfor %} 
    </form> 
    </body> 
</html> 

: 1340px * 0 픽셀입니다. 나는 심지어 명시 적으로 style = "height : 500px"를 주었지만 여전히 빈 양식을 제공합니다.

여기에 도움들에 대한 screenshot

감사입니다!

편집 :

Views.py : 나는 thenewboston의 채널에 의해 비디오 자습서 시리즈를 사용하고 있기 때문에

from django.shortcuts import render, get_object_or_404 
from .models import Structure, Record 

def index(request): 
    all_structures = Structure.objects.all() 
    return render(request, 'Structures/index.html', {'all_structures': all_structures}) 

def detail(request, structure_id): 
    #structure = Structure.objects.get(pk=structure_id) 
    structure = get_object_or_404(Structure, pk=structure_id) 
    return render(request, 'Structures/details.html', {'structure': structure}) 

def addRecord(request, structure_id, record.name, record.type, record.pos, record.long): 
    r = Record(structure='structure_id', name='record.name', type='record.type', pos='str(record.pos)', long='str(record.long)') 
    r.save() 
    return render(request, 'Structures/details.html', {'structure': structure}) 

, 나는 확실히 아직 이해하지, 난에서 사용하고있는 변수 addRecord는 알 수 없으므로 모델에서 사용하고 싶습니다. 여기에 모델 및 URL 파일도 있습니다

models.py :

from django.db import models 

class Structure(models.Model): 
    name = models.CharField(max_length=120) 
    path = models.CharField(max_length=200) 

    def __str__(self): 
     return self.name 

class Type(models.Model): 
    typename = models.CharField(max_length=50) 

    def __str__(self): 
     return self.typename 

class Record(models.Model): 
    structure = models.ForeignKey(Structure, on_delete=models.CASCADE) #each structure has many records, each per line 
    name = models.CharField(max_length=200) 
    type = models.ForeignKey(Type) 
    pos = models.IntegerField() 
    long = models.IntegerField() 

    def __str__(self): 
     return self.name 

urls.py : 당신이 상황에서 전달하는 all_structures의 값에 대한

from django.conf.urls import url 
from . import views 

app_name = 'Structure' 

urlpatterns = [ 
    # /structures/ 
    url(r'^$', views.index, name='index'), 

    # /structures/id 
    url(r'^(?P<structure_id>[0-9]+)/$', views.detail, name='detail'), 

    # /structures/addrecord 
    url(r'^(?P<structure_id>[0-9]+)/addrecord/$', views.addRecord, name='addrecord'), 
] 
+0

보기를 표시합니다. 'all_structures' 란 무엇이며 무엇이 포함되어 있습니까? 'record'는 어디에서 오는 것입니까? –

+0

필요한 코드를 모두 추가했습니다. –

+0

이것은 실제 코드가 아닙니다. 귀하의'addRecord' 정의에 잘못된 구문이 포함되어 있습니다. –

답변

0

봐 보기에서.

비어 있거나 전달되지 않으면 템플릿 코드에 따라 양식 필드가 표시되지 않습니다.

콘솔이나 템플릿에서 값을 인쇄 해보십시오. 그것이 디버깅하는 방법입니다.

희망이 도움이됩니다.

+0

비어 있지 않습니다. 색인 템플릿을 보면 2 개의 구조를 볼 수 있습니다. –

관련 문제