私は、volunteer_listテーブルからのボランティアのリストをリストするページを持っています。
Volunteer_listテーブルには、次のフィールドが含まれています。ボランティア名ボランティアの位置名作成日
このページから-メインページ次のページにボランティアのポジション名を渡す必要があります-連絡先ページ。ボランティアのポジションフィールドは50バイトのフィールドです。
連絡先ページのビューを定義するにはどうすればよいですか?また、連絡先ページの渡されたフィールドにアクセスするにはどうすればよいですか?
volunteer_list.html
<tr>
<th colspan=4 align="left"><label for="id_Volposition">Volunteer Position:</label></th>
<th colspan=.5 align="left"><a href="/signups/new/{{ v.position }}" class="username" <u>{{ v.volposition }}</u></a></th>
<tr> <td colspan="2" height="2" style="display:none"> </td> </tr>
</tr>
ここで気付いた場合は、v.positionをパラメーターとして渡して、signups / newページを呼び出します。次のことを知っておく必要があります。1。サインアップ/新しいページにアクセスするには、urls.pyをどのように定義しますか。 v.positionパラメーター2.サインアップ/新しいページでパラメーターにアクセスするにはどうすればよいですか
私のURLS.py
urlpatterns = patterns('',
(r'^new/$', sfp.view),
(r'^volunteer/$', volunteer_page),
(r'^vollist/$', volunteer_list),
(r'^volcont/$', volunteer_contact)
)
new / $はsfp.viewを呼び出します。これは私のviews.pyの関数です。そのビューは基本的に、すべての情報を収集するhtmlページをレンダリングします。
パラメータ「position」をこの関数に渡す方法を知る必要がありますか?
これは既存のコードです。
チュートリアルで与えられたような直接呼び出しであれば、問題はありません。
def detail(request、poll_id):
- sfp.viewのコード
views.py
sfp = SimpleFormProcessing(
form_class=VolunteerSignupForm,
form_2_model=volunteersignupform_2_model,
form_template='signups/create_contact_form.dmpl',
email_template='signups/response_email.dmpl',
email_html_template='signups/response_email_html.dmpl',
email_subject='Vibha Volunteer Signup',
email_sender='volunteer@vibha.org',
redirect_url='/signups/thanks/',
do_captcha=True)
code for simpleformprocessing:
class SimpleFormProcessing:
def __init__(self, form_class, form_2_model, form_template,
email_template, email_subject, email_sender, redirect_url,
do_captcha=False, record_ip_addr=False, email_html_template=None):
self.form_class = form_class
self.form_2_model = form_2_model
self.form_template = form_template
self.email_template = email_template
self.email_html_template = email_html_template
self.email_subject = email_subject
self.email_sender = email_sender
self.redirect_url = redirect_url
self.do_captcha = do_captcha
self.record_ip_addr = record_ip_addr
def view(self, request, initial={}):
Form = self.form_class
if self.do_captcha:
Form = form_with_captcha(Form, request)
if self.record_ip_addr:
Form = form_with_ipaddress(Form, request)
if request.method == 'POST':
# Try processing the form
if self.do_captcha and not accepts_cookies(request):
return our_flatpage('Please enable cookies and try again.')
else:
form = Form(request.POST)
if form.is_valid():
# The form is correct, process it
model = self.form_2_model(form)
if self.email_template:
text_content = render_to_string(self.email_template, {'model': model})
recipients = model.emailRecipients()
try:
bcc_recipients = model.emailBCCRecipients()
except:
bcc_recipients = None
msg = EmailMultiAlternatives(self.email_subject, text_content, self.email_sender,
recipients, bcc_recipients)
if self.email_html_template:
html_content = render_to_string(self.email_html_template, {'model': model})
msg.attach_alternative(html_content, "text/html")
msg.send()
return HttpResponseRedirect(self.redirect_url)
else:
# Show the form with errors
return render_to_response(self.form_template, {'form': form})
else:
# Show the empty form
form = Form(initial=initial)
if self.do_captcha: