我的表单名为 CreateTournamentForm ,应该在系统中创建新的锦标赛。当我在localhost工作时,一切都很好(不包括错误)。但是当我在我放置此应用程序的服务器上执行相同操作时,相同的表单在localhost上不起作用。页面正在刷新,我正在填写相同的表单(因为我在我的代码中创建它,如果不正确)。服务器停留在Ubuntu上(nginx + uwsgi)。
我的代码示例:
a)template.html:
% block content %}
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<form method="post" action="{{ request.path }}" enctype="multipart/form-data">
{% csrf_token %}
<table class="table" style="width: 23%">
<tr>
<td><label>Name:</label>
<td>{{ form.name }}</td>
</tr>
<tr>
<td><label>Start date:</label>
<td>{{ form.start }}</td>
</tr>
<tr>
<td><label>End date:</label>
<td>{{ form.end }}</td>
</tr>
<tr>
<td><label>Martial arts:</label>
<td>{{ form.type }}</td>
</tr>
<tr>
<td><label>Regulations:</label>
<td>{{ form.file }}</td>
</tr>
<tr>
<td><label>Info:</label>
<td>{{ form.description }}</td>
</tr>
<tr>
<td><input type="submit" class="btn btn-default btn-primary" value="Confirm"></td>
<td><a href="javascript:history.back()" class="btn btn-default btn-primary">Back</a></td>
</tr>
</table>
</form>
{% endblock %}
{% block additional_js %}
<script src="http://code.jquery.com/jquery-2.1.3.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script>
$(document).ready(function() {
$('.datepicker').datepicker();
});
</script>
{% endblock %}
b)models.py“:
class Tournament(models.Model):
name = models.CharField(max_length=50)
start = models.DateField()
end = models.DateField()
username = models.ForeignKey(User, null=True)
KYOKUSHIN = 'KYO'
SHOTOKAN = 'SHO'
TYPE_CHOICES = (
(KYOKUSHIN, 'kyokushin'),
(SHOTOKAN, 'shotokan')
)
type = models.CharField(max_length=3,
choices=TYPE_CHOICES,
default=None,
null=True)
coaches = models.ManyToManyField(Coach, verbose_name="Lista trenerow", blank=True)
file = models.FileField(upload_to=file, verbose_name="Nazwa pliku")
description = models.TextField(max_length=500)
@property
def relative_path(self):
return os.path.relpath(self.path, settings.MEDIA_ROOT)
def __unicode__(self):
return unicode(self.name + " " + self.start.strftime('%Y-%m-%d') + " " + self.end.strftime('%Y-%m-%d'))
c)forms.py:
class CreateTournamentForm(forms.ModelForm):
class Meta:
model = Tournament
fields = ('name', 'start', 'end', 'type', 'file', 'description', )
widgets = {
'start': forms.DateInput(format=('%d/%m/%Y'), attrs={'class': 'datepicker'}),
'end': forms.DateInput(format=('%d/%m/%Y'), attrs={'class': 'datepicker'})
}
d)views.py:
@login_required
def createTournament(request):
template = loader.get_template('createtournament.html')
if request.method == 'POST':
form = CreateTournamentForm(request.POST, request.FILES)
if form.is_valid():
user = User.objects.get(user=request.user)
tournament = Tournament(
name=form.cleaned_data.get("name"),
start=form.cleaned_data.get("start"),
end=form.cleaned_data.get("end"),
username=user,
type=form.cleaned_data.get("type"),
file=request.FILES.get("file"),
description=form.cleaned_data.get("description")
)
tournament.save()
Manager.objects.create(user_id=user, tournament=tournament)
return redirect('/user/')
else:
form = CreateTournamentForm()
return render_to_response('createtournament.html', RequestContext(request, {'form': form, }))
有人看到错误吗?或许还有另一个问题?感谢您的每一个回复:)