我正在使用Django 1.3制作一个带有Django 1.3的工作申请页面(我知道我应该更新,但那部分不在我手中),通过mod_wsgi使用apache,当用户试图查看上传的文件时遇到问题例如在提交的申请中恢复。
以下是尝试访问文件的页面的视图
def apply(request, ann_id):
user = UserManager(request)
okay = user.isOk(request)
if not okay:
raise Http404
username = user.data.get('userName')
if user.data.get('employeer') != "Company":
return render_to_response('lobbs/cannotApply.html', locals())
announcement = get_object_or_404(Announcements, id=ann_id)
validation_errors = []
applicantBen_error = ''
orgBen_error = ''
ast_error = ''
grade_error = ''
fpl_error = ''
resume_error = ''
reviewedSOD_error = ''
understand_error = ''
if request.method == 'POST':
form = LookupForm(request.POST, request.FILES)
if form.is_valid():
if announcement.type_id in [1,2,3]:
applicantBen = form.data.get('benefitApplicant','')
orgBen = form.data.get('benefitOrg','')
if not applicantBen:
applicantBen_error = ERROR_BENEFIT_APPLICANT
validation_errors.append(applicantBen_error)
if not orgBen:
orgBen_error = ERROR_BENEFIT_ORG
validation_errors.append(orgBen_error)
if announcement.type_id in [4,5]:
resumeFile = ''
try:
resumeFile = request.FILES['resume']
except KeyError:
resumeFile = ''
reviewSOD = form.data.get('reviewedSOD','')
if not resumeFile:
resume_error = ERROR_RESUME
validation_errors.append(resume_error)
if not reviewSOD:
reviewedSOD_error = ERROR_REVIEWED_SOD
validation_errors.append(reviewedSOD_error)
if announcement.type_id == 4:
astTitle = form.data.get('title','')
grade = form.data.get('grade','')
fpl = form.data.get('fpl','')
if not astTitle:
ast_error = ERROR_AST
validation_errors.append(ast_error)
if not grade:
grade_error = ERROR_GRADE
validation_errors.append(grade_error)
if not fpl:
fpl_error = ERROR_FPL
validation_errors.append(fpl_error)
if announcement.tempPromotion:
understand = form.data.get('understandTempPromotion','')
if not understand:
understand_error = ERROR_UNDERSTAND
validation_errors.append(understand_error)
if announcement.type_id == 5:
verify = form.data.get('verifyCurrPos','')
if not verify:
verify_error = ERROR_VERIFY
validation_errors.append(verify_error)
if not validation_errors:
newLookupObject = form.save(commit=False)
newLookupObject.announcement = announcement
newLookupObject.announceNum = announcement.announceNum
newLookupObject.userID = user.data.get('id')
newLookupObject.save()
sender = u"EMAIL"
subject = u"LOBBS - Application Received"
textMail = u"Hello %s,<br><br>Your application for %s (%s), has been entered into LOBBS. You will be notified of a selection by the person selecting applicants.<br><br><br>%s" % (user.data.get('userName'), announcement.title,announcement.announceNum, LOBBS_URL)
recipients = [user.data.get('email')]
msg = EmailMessage(subject, textMail, sender, recipients)
msg.content_subtype = "html"
msg.send()
return HttpResponseRedirect(reverse('lobbs.views.index'))
else:
#data = { 'announcement': announcement, 'announceNum': announcement.announceNum, 'userID': user.data.get('id') }
#form = LookupForm(data)
form = LookupForm(initial={'userName': user.data.get('userName'), 'phone': user.data.get('phone'),
'email': user.data.get('email'), 'org': user.data.get('org'), 'announcement': announcement,
'announceNum': announcement.announceNum, 'userID': user.data.get('id')})
return render_to_response('lobbs/apply.html', locals(), context_instance=RequestContext(request))
这是它正在使用的模板
{% extends "base.html" %}
{% block header %}
{% include 'lobbs/apply_header.html' %}
{% endblock %}
{% block main_content %}
{% load url from future %}
<br />
<div align="center">
<form enctype="multipart/form-data" name="software" action="{% url 'lobbs_apply' ann_id=announcement.id %}" method="post" onreset ="return confirm('Erase ALL data and start over?')">
{% csrf_token %}
<table width = "600" cellspacing = "0" cellpadding = "2" align = "center" border = 0>
<tr>
<td bgcolor = "#eaeaea" colspan="2">
<font color="red">
{% for field in form %}
{% if field.errors %}
{{ field.label_tag }} - {{ field.errors }}
{% endif %}
{% endfor %}
{% if validation_errors %}
<ul>
{% for item in validation_errors %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% endif %}
</font>
</td>
</tr>
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>Opp No</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ announcement.announceNum }}</td>
</tr>
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>Title</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ announcement.title }}</td>
</tr>
{% if announcement.type.id == 1 or announcement.type.id == 2 or announcement.type.id == 3 %}
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>Description</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ announcement.description }}</td>
</tr>
{% else %}
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>{% if announcement.type.id != 5 %}Statement of Duties / {% endif %}Position Description</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{% if announcement.statementOfDuties%} <a href="{{ announcement.statementOfDuties.url }}">{% if announcement.type.id != 5 %}Statement of Duties / {% endif %}Position Description</a>{% endif %}</td>
</tr>
{% endif %}
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>Type</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ announcement.type }}</td>
</tr>
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>{{ form.userName.label_tag }}</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.userName }}</td>
</tr>
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>{{ form.phone.label_tag }}</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.phone }}</td>
</tr>
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>{{ form.email.label_tag }}</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.email }}</td>
</tr>
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>{{ form.org.label_tag }}</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.org }}</td>
</tr>
{% if announcement.type_id = 4 %}
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>{{ form.title.label_tag }}</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.title }}</td>
</tr>
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right" nowrap="nowrap"><strong>{{ form.grade.label_tag }}</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.grade }}</td>
</tr>
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>{{ form.fpl.label_tag }}</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.fpl }}</td>
</tr>
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"> </th>
<td bgcolor = "#eaeaea" valign="top" align="left">SNIP</td>
</tr>
{% endif %}
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>{{ form.supApproval.label_tag }}</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.supApproval }}</td>
</tr>
{% if announcement.type_id = 1 or announcement.type_id = 2 or announcement.type_id = 3 %}
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>{{ form.benefitApplicant.label_tag }}</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.benefitApplicant }}</td>
</tr>
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>{{ form.benefitOrg.label_tag }}</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.benefitOrg }}</td>
</tr>
{% endif %}
{% if announcement.type_id = 4 or announcement.type_id = 5 %}
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"> </th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.reviewedSOD }} {{ form.reviewedSOD.label_tag }}</td>
</tr>
{% endif %}
{% if announcement.type_id = 4 %}
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"> </th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.understandTempPromotion }} {{ form.understandTempPromotion.label_tag }}</td>
</tr>
{% endif %}
{% if announcement.type_id = 5 %}
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"> </th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.verifyCurrPos }} {{ form.verifyCurrPos.label_tag }}</td>
</tr>
{% endif %}
<tr>
<th bgcolor = "#eaeaea" valign = "top" align = "right"><strong>{{ form.resume.label_tag }}</strong></th>
<td bgcolor = "#eaeaea" valign="top" align="left">{{ form.resume }}<br /><font color="red">*</font> LOBBS is not intended to collect Personally Identifiable Information (PII) from any users. Applicants are highly discouraged from including any PII in documents uploaded into the system.</td>
</tr>
<tr>
<td colspan="2"><INPUT TYPE = "submit" NAME = "Operation" VALUE = "Apply"> <INPUT TYPE = "reset" VALUE = "Reset"></td>
</tr>
</table>
</form>
</div>
<br />
{% endblock %}
当点击文件的链接时,浏览器会说网页不可用,但网址跟随文件存储在服务器上的路径。有什么方法可以解决这个问题吗?
答案 0 :(得分:0)
无论出于何种原因,问题在于服务器在更新文件时落后了,并且忽略了为解决问题而实施的更改几天。之后它完美地运作了。