2011-01-23 11 views
0

私はジャンゴ(V2)へのDefinitive Guideのあなたが見てみたい場合はジャンゴ余り解析できませんでした:

がここにトレースバックだ次られた「電子メール」から「-mail」を http://dpaste.com/344698/

それは私にこのエラーを与える:

TemplateSyntaxError at /contact/ 

Could not parse the remainder: '-mail' from 'e-mail' 
Template error 

In template /home/jwxie/django-dev/mysite/contact/template/contact_form.html, error at line 5 
and line 5 is {% block content %} 

私はviews.py

from django.shortcuts import render_to_response 
from django.http import HttpResponseRedirect, HttpResponse 
from django.core.mail import send_mail 

def contact(request): 
    display_error = [] 
    if request.method == 'POST': 
     if not request.POST.get('subject',''): 
      display_error.append('Enter a subject') 
     if not request.POST.get('message',''): 
      display_error.append('Enter a message') 
     if not request.POST.get('e-mail') and '@' not in request.POST['e-mail']: 
      display_error.append('Enter a valid e-mail address') 
     if not display_error: 
      send_mail(
         request.POST['subject'], 
         request.POST['message'], 
         request.POST.get('e-mail','[email protected]'), 
         ['[email protected]'], 
      ) 
      return HttpResponseRedirect('/contact/thanks/') 
    return render_to_response('contact_form.html',{ 
       'subject': request.POST.get('subject',''), 
       'message': request.POST.get('message',''), 
       'e-mail': request.POST.get('e-mail',''), 
       'display_error': display_error, 
       }) 

def contact_thanks(request): 
    return HttpResponse('Thanks') 
に持っていたコード

これは私がアプリとして接触したcontact_form.html

{% extends "base.html" %} 

{% block title %} Contact {% endblock %} 
{% block content %} 
{% block content-h1 %}<p>Feel free to contact us!</p> {% endblock %} 

<form action="/contact/" method="post"> 
<p>Subject: <input type="text" name="subject" value="{{ subject }}"></p> 
<p>Your e-mail (optional): <input type="text" name="e-mail" value="{{ e-mail }}"> </p> 
<p>Message: <textarea name="message" rows="10" cols="50">{{ message }}</textarea></p> 
<input type="submit" value="Submit"> 
</form> 

{% if display_error %} 
<ul> 
{% for error in display_error %} 
<li>{{error}}</li> 
{% endfor %} 
</ul> 
{% endif %} 
{% endblock %} 

内のコードで、構造は次のようになります。個人用サイト/連絡先と、それは、独自のテンプレートを個人用サイト/連絡先/テンプレート を持っている私は、設定確信しています。 pyは正しいです...

あなたはどう思いますか?どんな助けもありがとう。私はちょうどサンプルコードで遊んでいます。

答えて

2

なぜ「電子メール」と書いていますか?テンプレート変数はPythonの変数名である必要はありませんか? "Eメール"?

http://docs.djangoproject.com/en/dev/topics/templates/#variables

それは

Variable names consist of any combination of alphanumeric characters and the underscore ("_").

+0

非常に素晴らしい、ロット氏は述べています。実際、作者は間違いを犯しました。指摘してくれてありがとう。彼らは - ビューとテンプレートの両方で使用しました – CppLearner

関連する問題