What do you mean, If i take it out of the ctx dictionary how do I pass it. if I just declare the @csrf_protect I still get the token error trying to post my form, infact the csrf issue is the only thing I have left to fix. How are you supposed to do the csrf token because im following the documentation and its not working. I tried what you suggested removing the declaration no luck.
On Thursday, May 15, 2014 8:12:33 AM UTC-6, donarb wrote: > > On Wednesday, May 14, 2014 11:35:46 PM UTC-7, G Z wrote: >> >> So I read the documentation on passing csrf tokens, however its giving me >> an issue i think its because im trying to pass it as a dictonary variable >> with my form and customers. >> >> This is from the documentation >> >> from django.views.decorators.csrf import csrf_protectfrom django.shortcuts >> import render >> @csrf_protectdef my_view(request): >> c = {} >> # ... >> return render(request, "a_template.html", c) >> >> >> >> from django.shortcuts import render >> from django.http import HttpResponse >> from vmware.models import Customer >> from django.shortcuts import render_to_response >> from vmware.models import Vms >> from .forms import SignUpForm >> from vmware.models import Vmspecs >> from django.views.decorators.csrf import csrf_protect >> >> @csrf_protect >> def index(request): >> c = {} >> form = SignUpForm(request.POST or None) >> if form.is_valid(): >> save_it = form.save(commit=False) >> save_it.save() >> customers = Customer.objects.all() >> ctx = { 'customers':customers, 'form':form, c} >> return render_to_response('index.html', ctx) >> >> >> >> this is the error i get >> >> >> Environment: >> >> >> Request Method: GET >> Request URL: http://23.239.206.142:8000/ >> >> Django Version: 1.6.4 >> Python Version: 2.7.3 >> Installed Applications: >> ('django.contrib.admin', >> 'django.contrib.auth', >> 'django.contrib.contenttypes', >> 'django.contrib.sessions', >> 'django.contrib.messages', >> 'django.contrib.staticfiles', >> 'vmware') >> Installed Middleware: >> ('django.contrib.sessions.middleware.SessionMiddleware', >> 'django.middleware.common.CommonMiddleware', >> 'django.middleware.csrf.CsrfViewMiddleware', >> 'django.contrib.auth.middleware.AuthenticationMiddleware', >> 'django.contrib.messages.middleware.MessageMiddleware', >> 'django.middleware.clickjacking.XFrameOptionsMiddleware') >> >> >> Traceback: >> File >> "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in >> get_response >> 101. resolver_match = >> resolver.resolve(request.path_info) >> File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" >> in resolve >> 337. for pattern in self.url_patterns: >> File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" >> in url_patterns >> 365. patterns = getattr(self.urlconf_module, "urlpatterns", >> self.urlconf_module) >> File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" >> in urlconf_module >> 360. self._urlconf_module = import_module(self.urlconf_name) >> File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" >> in import_module >> 40. __import__(name) >> File "/root/djangoprojects/provisioning/provisioning/urls.py" in <module> >> 7. url(r'^customers/', include('vmware.urls')), >> File >> "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in >> include >> 26. urlconf_module = import_module(urlconf_module) >> File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" >> in import_module >> 40. __import__(name) >> File "/root/djangoprojects/provisioning/vmware/urls.py" in <module> >> 5. from vmware import views >> >> Exception Type: SyntaxError at / >> Exception Value: invalid syntax (views.py, line 19) >> >> >> > Specifically, you're passing 'c' into the ctx dictionary, but it has no > key, that's the syntax error. But that c dictionary is redundant anyway > since you've created your own context dictionary. Just remove the > declaration of that object and don't pass it into the dictionary. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/217fde20-b061-46f1-bb57-68812cf81bca%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.