2016-12-07 64 views
1

如何讓我的表單顯示?表單未出現

到目前爲止只有html標題和提交按鈕正在顯示。

Views.py

from django.shortcuts import render 

# Create your views here. 

from signups.forms import SignUpForm 

def home(request): 

    form = SignUpForm() 

    return render(request,'signup.html') 

signup.html:

<!doctype html> 

    <html lang="en"> 

     <head> 

     </head> 

     <body> 
      <h1>Join Now !!!</h1> 
       <form action='' method='POST'> 
        {{ form.as_p }} 

        <input type='submit'> 
       </form> 
     </body> 

    </html> 

回答

1

你需要將它傳遞給模板!

return render(request,'signup.html',{'form': form }) 

然後在模板中顯示它!

{{form.as_p}}

+0

太感謝你了,它的工作:-) –

+0

你是最歡迎的。我很高興得到了幫助。既然你在這裏還是新手,我是否可以指出在這裏說'感謝'的首選方式是通過提高投票的好問題和有用的答案(一旦你有足夠的聲望這樣做),並接受最有幫助的答案到任何問題你問(這也給你一個小小的提升你的聲譽)。 [當某人回答](http://stackoverflow.com/help/someone-answers) – e4c5