Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango POST dict empty despite form
    primarykey
    data
    text
    <p>Django 1.4.1. I have a form which appears to have all proper values present in the html yet the POST dict appears empty.</p> <p>views.py (relevant portion):</p> <pre><code>@login_required def event(request, event_id): event = Event.objects.get(pk=event_id) crew = event.userprofile_set.all() current_user = request.user.get_profile() if current_user in crew: current_user_is_not_crew = False elif request.user == event.host: current_user_is_not_crew = False else: current_user_is_not_crew = True if event.date &gt; datetime.now(): future_event = True else: future_event = False context = RequestContext(request) context['event'] = event context['crew'] = crew context['current_user_is_not_crew'] = current_user_is_not_crew context['future_event'] = future_event return render_to_response('event.html', context) def commit(request): """ Commit user to event. Check if enough members (2 including event creator) are taking part to publish the event. If there are, mark sufficient_participants Boolean and publish the event to Facebook. clashing_commitment checks that request user is not already committed to an event on this day. If she is they will not be allowed to commit to this. """ member = request.user.get_profile() event_id = request.POST.get('event_id','') print event_id event = Event.objects.get(pk=event_id) event_less_3_hours = event.date - timedelta(hours=3) event_plus_3_hours = event.date + timedelta(hours=3) clashing_commitment = Event.objects.filter(userprofile__exact=member).\ filter(date__range=(event_less_3_hours, event_plus_3_hours)) crew = event.userprofile_set.all() print crew context = RequestContext(request) if clashing_commitment: context['event'] = event context['crew'] = crew messages.add_message(request, messages.INFO, 'You are already committed to another event at this time. \ You cannot commit to two simultaneous events. Sorry! \ &lt;a href="mailto:me@gmail.com"&gt;Ask admin&lt;/a&gt; to remove you from other event if necessary.') return render_to_response('event.html', context) try: # cronix test page token: graph = GraphAPI("CAAk6zW7VBJL9eUZD") # Publish Facebook event on page eventdate = event.date date_iso = eventdate.isoformat() date_iso += '+0100' graph.post( path = '/449/events', retry=1, name = event.name, description = event.description, location = event.location, start_time = date_iso, ) # To post event image, retrieve all Page events and identify current event # by its precise date in ISO format as captured above. # TODO This is a hacky, error-prone means of identifying # events and needs to be fixed. fb_events = graph.get('/449/events') fb_events = fb_events['data'] for item in fb_events: if item["start_time"] == date_iso: fb_event = item fb_event_id = fb_event.values()[0] fb_event_path = fb_event_id + '/picture' # Get appropriate, environment-specific root url for urllib call below. # TODO Set two img_url variables and wrap urllib2.urlopen call # in try/except as it is error prone try: if os.environ['ENV'] == 'staging': img_url = 'http://www.mysite.org.uk//img/logo-fb.jpg' except: img_url = 'http://localhost:8000/static/img/logo.png' print img_url graph.post( path = fb_event_path, source = urllib2.urlopen(img_url)) except GraphAPI.OAuthError, e: print e.message return redirect('commit') member.event_commitments.add(event) crew = event.userprofile_set.all() if crew.count() &gt; settings.EVENT_PUB_COMMITTED_CRITICAL_MASS and event.sufficient_participants == 0: event.sufficient_participants = 1 event.save() publish_event = True context['event'] = event context['crew'] = crew messages.add_message(request, messages.SUCCESS, 'You have committed to this event.') return render_to_response('event.html', context) </code></pre> <p>urls.py (as requested by commenter):</p> <pre><code>from crewcal.views import user, log_in from django.conf.urls import patterns, include, url from django.contrib.auth.views import login, logout from crewcal import models, views from crewcal.forms import CustomRegistrationForm # from crewcal.forms import RegistrationFormUniqueEmail urlpatterns = patterns('', # Examples: url(r'^$', 'crewcal.views.index', name='home'), # url(r'^ssc/', include('ssc.foo.urls')), url(r'^events/(?P&lt;event_id&gt;\d+)/$', 'crewcal.views.event', name='events'), url(r'^events/new/$', 'crewcal.views.new_event', name='new_event'), url(r'^commit/$', 'crewcal.views.commit', name='commit'), url(r'^users/(?P&lt;user_name&gt;[A-Za-z]+)/$', 'crewcal.views.user', name="user-profile"), url(r'^users/(?P&lt;user_name&gt;\d+)/$', 'crewcal.views.user', name="user-profile"), url(r'^', include('registration.backends.default.urls')), url(r'^register/$', 'RegistrationView', {'form_class':CustomRegistrationForm, 'backend':'registration.backends.default.DefaultBackend' }, name='registration_register'), # For Registration simple, one-step login # url(r'^', include('registration.backends.simple.urls')), url(r'^facebook/', include('django_facebook.urls')), # (r'^$', include('django_facebook.auth_urls')), url(r'^messages/', include('postman.urls')), # url(r'^event/$', views.object_list, {'model': models.Event}), url(r'^accounts/', include('registration.urls')), # url(r'^register/$', register, name='join'), url(r'^login/$', 'django.contrib.auth.views.login'), url(r'^logout/$', logout, {'next_page': '/'}, name='logout'), url(r'^log_in/$', log_in, name='log_in'), </code></pre> <p>Here's the form rendered in the page:</p> <pre><code>&lt;p&gt; &lt;form action="/commit/" method="post" id="event-commit"&gt; &lt;input type="hidden" name="event_id" id="event_id" value="4"&gt; &lt;input type="submit" value="Commit to this event &amp;raquo;" class="btn")"&gt; &lt;div style='display:none'&gt;&lt;input type='hidden' name='csrfmiddlewaretoken' value='XXOqtkkxYQ0zAN1sv3KYxVD8ljhjMpit' /&gt;&lt;/div&gt; &lt;/form&gt; &lt;/p&gt; </code></pre> <p>But the consequent page breaks because the event_id (or anything else) is present in the POST dictionary:</p> <pre><code>Exception Type: ValueError Exception Value: invalid literal for int() with base 10: '' ... request "&lt;WSGIRequest\npath:/commit/,\nGET:&lt;QueryDict: {}&gt;,\nPOST:&lt;QueryDict: {}&gt;,\nCOOKIES: ... </code></pre> <p>This is happening in my Heroku staging environment but not locally. Any ideas? Thanks.</p>
    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