Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango: SyntaxError 'unexpected EOF' while saving a Form
    primarykey
    data
    text
    <p>I have a settings page which has two forms for handling the settings for two different Models. The Profile model form works. The Chef model form doesn't. The form fails gracefully, and isn't throwing a Django error page - so in using pdb, I found the form is not valid, and is throwing a Syntax Error.</p> <p>I'm confused as to which field this error is coming form. Any help would be greatly appreciated. Thanks!</p> <p><strong>Error:</strong></p> <pre><code>*** SyntaxError: SyntaxError('unexpected EOF while parsing', ('&lt;string&gt;', 0, 0, '')) </code></pre> <p><strong>HTML</strong> </p> <pre><code> {% if form.is_multipart %} &lt;form enctype="multipart/form-data" method="post" action="."&gt;{% csrf_token %} {% else %} &lt;h3&gt;Profile Settings&lt;/h3&gt; &lt;form method="post" action="."&gt; {% endif %} &lt;dl&gt; &lt;dt&gt;{{form.photo.label}}&lt;/dt&gt; &lt;dd&gt;{{form.photo}}&lt;/dd&gt; &lt;dt&gt;{{form.firstname.label}}&lt;/dt&gt; &lt;dd&gt;{{form.firstname}}&lt;/dd&gt; &lt;dt&gt;{{form.lastinitial.label}}&lt;/dt&gt; &lt;dd&gt;{{form.lastinitial}}&lt;/dd&gt; &lt;/dl&gt; &lt;button type="submit"&gt;Save&lt;/button&gt; &lt;/form&gt; &lt;h3&gt;Chef Settings&lt;/h3&gt; &lt;form action="{% url edit_chef chef.id %}" method="post" accept-charset="utf-8"&gt;{% csrf_token %} &lt;dl&gt; &lt;dt&gt;{{chefform.category.label}}&lt;/dt&gt; &lt;dd&gt;{{chefform.category}}&lt;/dd&gt; &lt;dt&gt;{{chefform.price.label}}&lt;/dt&gt; &lt;dd&gt;{{chefform.price}}&lt;/dd&gt; &lt;dt&gt;{{chefform.meal.label}}&lt;/dt&gt; &lt;dd&gt;{{chefform.meal}}&lt;/dd&gt; &lt;dt&gt;{{chefform.language.label}}&lt;/dt&gt; &lt;dd&gt;{{chefform.language}}&lt;/dd&gt; &lt;dt&gt;{{chefform.address.label}}&lt;/dt&gt; &lt;dd&gt;{{chefform.address}}&lt;/dd&gt; &lt;dt&gt;{{chefform.neighborhood.label}}&lt;/dt&gt; &lt;dd&gt;{{chefform.neighborhood}}&lt;/dd&gt; &lt;dt&gt;{{chefform.city.label}}&lt;/dt&gt; &lt;dd&gt;{{chefform.city}}&lt;/dd&gt; &lt;dt&gt;{{chefform.state.label}}&lt;/dt&gt; &lt;dd&gt;{{chefform.state}}&lt;/dd&gt; &lt;dt&gt;{{chefform.menu.label}}&lt;span id="rBann" class="minitext"&gt;1000&lt;/span&gt;&lt;/dt&gt; &lt;dd&gt;{{chefform.menu}}&lt;/dd&gt; &lt;/dl&gt; &lt;button type="submit"&gt;Save&lt;/button&gt; &lt;/form&gt; </code></pre> <p><strong>Chef Form</strong></p> <pre><code>class ChefForm(forms.ModelForm): class Meta: model = Chef fields = ('category','meal','price','language','address','neighborhood','city','state', 'country', 'menu') category = forms.ChoiceField( label=_("Food style"), choices=([('Afghan','Afghan'),('African','African'),('American','American'),]), required=True) meal = forms.ModelMultipleChoiceField( label=_("What is your best meal?"), queryset=Meal.objects.all(), required=True) price = forms.IntegerField( label=_("Price per person"), widget=forms.TextInput(), required=True) language = forms.ModelMultipleChoiceField( label=_("Languages spoken"), queryset=Language.objects.all(), required=True) address = forms.CharField( label=_("Your Address"), widget=forms.TextInput(), required=True) neighborhood = forms.CharField( label=_("Your Neighborhood"), widget=forms.TextInput(), required=True) city = forms.CharField( label=_("Your City"), widget=forms.TextInput(), required=True) state = forms.CharField( label=_("Your state"), widget=forms.TextInput(), required=True) country = forms.CharField( label=_("Your country"), widget=forms.TextInput(), required=True) menu = forms.CharField( label=_("What's unique about your cooking &amp; home? Pets? Have a family or roommates?"), widget=forms.TextInput(), required=True) def __init__(self, *args, **kwargs): super(ChefForm, self).__init__(*args, **kwargs) self.fields['price'].widget.attrs = { 'placeholder':'10'} self.fields['menu'].widget.attrs = { 'placeholder':'Tacos!'} </code></pre> <p><strong>View:</strong></p> <pre><code>@login_required def edit_chef(request, chef_id, template_name="chef/newchef.html"): chef = get_object_or_404(Chef, id=chef_id) if request.user != chef.cook: return HttpResponseForbidden() if request.method == 'POST': import pdb; pdb.set_trace() chefform = ChefForm(request.POST, instance=chef) if chefform.is_valid(): chefform.save() return HttpResponseRedirect('/users/%d/' % request.user.id) else: return HttpResponseRedirect('/users/%d/' % request.user.id) data = { "chef":chef, "chefform":chefform } return render_to_response(template_name, data, context_instance=RequestContext(request)) </code></pre> <p>To add more information to this bug, I was able to pull up this broken pipe error:</p> <pre><code>[29/Jan/2011 09:20:24] "POST /chef/1/edit/ HTTP/1.1" 200 104804 Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 281, in run self.finish_response() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 321, in finish_response self.write(data) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 400, in write self.send_headers() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 464, in send_headers self.send_preamble() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 382, in send_preamble 'Date: %s\r\n' % http_date() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 322, in write self.flush() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 301, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size]) error: [Errno 32] Broken pipe ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 53340) Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock self.process_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 310, in process_request self.finish_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 323, in finish_request self.RequestHandlerClass(request, client_address, self) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 562, in __init__ BaseHTTPRequestHandler.__init__(self, *args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 641, in __init__ self.finish() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 694, in finish self.wfile.flush() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 301, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size]) error: [Errno 32] Broken pipe ---------------------------------------- [29/Jan/2011 09:20:27] "GET /users/2/ HTTP/1.1" 200 114593 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload