我有一个名为Question的模型.模型允许用户创建新问题.我正在尝试使用对象的查询集填充多个表单.当我尝试使用查询集初始化时出现问题.我收到这个错误
'Question' object is not iterable
File "C:\mysite\pet\views.py" in DisplayAll
294. formset = form(initial=q)
Run Code Online (Sandbox Code Playgroud)
models.py
class Question(models.Model):
question= models.CharField(max_length=500)
user = models.ForeignKey(User)
Run Code Online (Sandbox Code Playgroud)
形式
class QuestionForm(forms.ModelForm):
question= forms.CharField(required=True,max_length=51)
class Meta:
model = Question
fields = ('question',)
Run Code Online (Sandbox Code Playgroud)
意见
def DisplayAll(request):
q = Question.objects.filter(user=request.user)
form = formset_factory(QuestionForm)
formset = form(initial=q)
return render(request,'question.html',{'formset':formset})
Run Code Online (Sandbox Code Playgroud)
模板
{% for f in formset %}
{{f}}
{% endfor %}
Run Code Online (Sandbox Code Playgroud) 我正在尝试建立一个由django + uwsgi + ngnix组成的生产服务器.我正在关注的教程位于http://www.panta.info/blog/3/how-to-install-and-configure-nginx-uwsgi-and-django-on-ubuntu.html
生产服务器正在运行,因为我可以在调试打开时看到管理页面,但是当我关闭调试时.它再次显示服务器错误(500).我不知道该怎么办 .Ngnix应该服务于django请求.我现在很无能为力,请有人帮助我.
我的/etc/nginx/sites-available/mysite.com
server {
listen 80;
server_name mysite.com www.mysite.com;
access_log /var/log/nginx/mysite.com_access.log;
error_log /var/log/nginx/mysite.com_error.log;
location / {
uwsgi_pass unix:///tmp/mysite.com.sock;
include uwsgi_params;
}
location /media/ {
alias /home/projects/mysite/media/;
}
location /static/ {
alias /home/projects/mysite/static/;
}
}
Run Code Online (Sandbox Code Playgroud)
我的/etc/uwsgi/apps-available/mysite.com.ini
[uwsgi]
vhost = true
plugins = python
socket = /tmp/mysite.com.sock
master = true
enable-threads = true
processes = 2
wsgi-file = /home/projects/mysite/mysite/wsgi.py
virtualenv = /home/projects/venv
chdir = /home/projects/mysite
touch-reload = /home/projects/mysite/reload
Run Code Online (Sandbox Code Playgroud)
我的settings.py
root@localhost:~# cat /home/projects/mysite/mysite/settings.py
# Django settings …Run Code Online (Sandbox Code Playgroud) 我有一个简单的应用程序,允许您将图像上传到服务器,它设置在我的生产服务器上,由 django + uwsgi + ngnix 组成。
尝试上传图像时遇到问题。我收到以下错误:
错误
502 Bad Gateway
nginx/1.2.1
Run Code Online (Sandbox Code Playgroud)
功能:
def upload(request):
form = ImageForm()
context = {'form':form,}
context.update(csrf(request))
if request.POST:
form = ImageForm(request.POST, request.FILES)
if form_is.valid():
image = request.FILES.get('image')
CarPhoto.objects.create(user=request.user,cars=1,description='dwq',image=image)
return HttpResponseRedirect(reverse('transformer:kevin'))
return render_to_response('image.html',context,context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
模板
<form method="POST" enctype="multipart/form-data" action=".">
{% csrf_token %}
<div id="c">image</div> {{form.image}}
<input type = "submit" value= "add" id="box2"/>
</form>
Run Code Online (Sandbox Code Playgroud)
mysite.com_error.log
"uwsgi://unix:///tmp/mysite.com.sock:", host: "174.414.14.551", referrer: "http://174.414.14.551/car/upload"
2013/06/26 12:07:39 [error] 28870#0: *5 sendfile() failed (32: Broken pipe) while sending request to upstream, client: …Run Code Online (Sandbox Code Playgroud) django ×3