how do you iterate over a list in django - django

This is a sample view code
def link(reqest):
title = ['Home Page', 'Current Time', '10 hours later']
return render_to_response('time.html', title)
This is a sample template code
{% for item in title %}
{{item}}
{% if not forloop.last %} | {% endif %}
{% endfor %}
This is a sample url code
(r'^now/$', current_time, link),
However, I get an error
TypeError at /now/
'function' object is not iterable
I know this works in Python. How do you iterate in django, then?
Thank you for any input in advance!
from django error page
TypeError at /now/
'function' object is not iterable
Request Method: GET Request URL:
http://127.0.0.1:8000/now/ Django
Version: 1.2.3 Exception Type:
TypeError Exception Value:
'function' object is not iterable
Exception Location:
C:\Python27\lib\site-packages\django\core\urlresolvers.py
in resolve, line 121 Python
Executable: C:\Python27\python.exe
Python Version: 2.7.0 Python Path:
['C:\Documents and
Settings\JohnWong\workspace\mysite\mysite',
'C:\Documents and
Settings\JohnWong\workspace\mysite',
'C:\Python27', 'C:\Python27\DLLs',
'C:\Python27\lib',
'C:\Python27\lib\lib-tk',
'C:\Python27\lib\plat-win',
'C:\Python27\lib\site-packages',
'C:\WINDOWS\system32\python27.zip']
Server time: Sat, 16 Oct 2010
22:45:36 -0400
Environment:
Request Method: GET Request URL:
http://127.0.0.1:8000/now/ Django
Version: 1.2.3 Python Version: 2.7.0
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages'] Installed
Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback: File
"C:\Python27\lib\site-packages\django\core\handlers\base.py"
in get_response
91. request.path_info) File
"C:\Python27\lib\site-packages\django\core\urlresolvers.py" in resolve
217. sub_match = pattern.resolve(new_path) File
"C:\Python27\lib\site-packages\django\core\urlresolvers.py" in resolve
121. kwargs.update(self.default_args)
Exception Type: TypeError at /now/
Exception Value: 'function' object is
not iterable

You're trying to iterate over this thing, right?
title = ['Home Page', 'Current Time', '10 hours later']
Well, link is a function (you def'd it, remember?) so you can't just access title like that. That code will not work in Python. If you try this:
def link(reqest):
title = ['Home Page', 'Current Time', '10 hours later']
return render_to_response('time.html', title)
for item in link.title:
print title
You'll also get an error:
AttributeError: 'function' object has no attribute 'title'

You haven't made a context. You're passing a list where a context is needed, and using a view name in the template. Try this:
def link(request):
c = Context()
c['titles'] = ['Home Page', 'Current Time', '10 hours later']
return render_to_response('time.html', c)
and then:
{% for item in titles %}
{{item}}
{% if not forloop.last %} | {% endif %}
{% endfor %}

This is about how you're specifying the context for the template, I believe. Try returning a dictionary instead, with title inside of it:
return render_to_response('time.html', {"title":title})
and then iterating like:
{% for item in title %}
{{ item }}
etc.
Note that you need two brackets around item in the loop, rather than one.
Now that you've added the extra info, I see the error is coming before the view is even executed (though you would have had a few once you got there, too).
The URL specification takes a callable as it's second argument. You have a couple of variables on there -
(r'^now/$', current_time, link),# that isn't a proper reference to the 'link' function, and it can't come second
It should be something like
(r'^articles/(?P<current_time>\(?P<link>)/$', 'project_name.views.link'), #the second tuple element is the view function
and then to accommodate the variables you are apparently passing in the URL, (also, make sure to have 'request' and not 'reqest' to keep things straight)
def link(request,current_time,link):

Related

'render' object has no attribute 'GET'

I'm working on a web application for a uni project using django and postgresql. This is my first time working with django forms and when trying to render any of them for a test run and to figure out the views the render fails with the above error message.
I have worked with Django beforehand but this is my first time working with forms -previously, I'd done object creation and edits through API views. I can't find where my code is wrong, but I've tried rewording it, moving lines around to see if it helps (it hasn't,) and even avoiding inheritance and trying to word it as a straightforward form (hasn't helped either.) I have four different forms but they all provide the same error message, so I'm just gonna show one user model extension that I'm not too confident about for an example, in case there's more wrong than I've realized.
This is the code I've got
class JdTform(UserCreationForm):
telefono = forms.IntegerField()
class Meta(UserCreationForm.Meta):
fields = [
'telefono'
]
labels = {
'telefono': 'teléfono'
}
widgets = {
'telefono': forms.NumberInput()
}
def jdt_form_view(request):
if request.method == 'GET':
form = JdTform()
return render(request, 'personas/formu_jdt.html', {'form': form})
if request.method == 'POST':
form = JdTform(request.POST)
if form.is_valid():
user = form.save()
fono = form.cleaned_data.get('telefono')
jdt = jefeDeTaller(telefono=fono, u=user)
jdt.save()
return redirect('cal_fecha')
<html lang="en">
<head>
<meta charset="utf-8">
<title>Gestor de Trabajo</title>
</head>
<body>
<header>
<h1>My Site</h1>
</header>
<main>
<h2>Sign up</h2>
<form action="/your-name/" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
</main>
</body>
</html>
urlpatterns = [
path('calendario/<int:ano>/<int:mes>/', views.calendario_mes, name='cal_fecha'),
path('usuarios/jefedetaller/', views.jdt_form_view, name='formulario_jdt'),
The error message I receive on the debug page is
AttributeError at /usuarios/jefedetaller/
'render' object has no attribute 'get'
with traceback
Request Method: GET
Request URL: http://127.0.0.1:8000/usuarios/jefedetaller/
Django Version: 2.2.1
Python Version: 3.5.1
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'gestor']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'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 "C:\Users\Flavio\Envs\3dmente\lib\site-packages\django\core\handlers\exception.py" in inner
34. response = get_response(request)
File "C:\Users\Flavio\Envs\3dmente\lib\site-packages\django\utils\deprecation.py" in __call__
96. response = self.process_response(request, response)
File "C:\Users\Flavio\Envs\3dmente\lib\site-packages\django\middleware\clickjacking.py" in process_response
26. if response.get('X-Frame-Options') is not None:
Exception Type: AttributeError at /usuarios/jefedetaller/
Exception Value: 'render' object has no attribute 'get'
With this specific model, the idea is to create a user object, link it directly with a jdt object, and pass the fono information with this instantiation.
Thank you very much beforehand if you can help!

NoReverseMatch in Django for username pass to view

I'm working on a basic Django app (just learning, this is my third small project), and I'm trying to add links to allow a list of every post a user has made. I've got the URLS being created OK (domain/posts/username), and I want this to link to a view (that I've already created, and which works when the parameters I want to pass are hard-coded to a single value), passing the positional arguments to the view. However, I'm running aground on the RegEx / Urls part of things. I think this is the relevant info:
urls.py:
urlpatterns = [
url(r'^create/', views.create, name='create'),
url(r'^(?P<pk>[0-9]+)/upvote', views.upvote, name='upvote'),
url(r'^(?P<pk>[0-9]+)/downvote' , views.downvote, name='downvote'),
url(r'^userposts/(?P<user>[.]+)', views.userposts, name='userposts')
views.py
def userposts(request,user):
posts = models.Post.objects.filter(url__contains=user)
return render(request, 'posts/userposts.html', {'posts': posts})
home.html
a href="{{ post.url}}">{{ post.title }}</a><br/>{{ post.pub_date_pretty }} by
{{ post.author.username }}</td>
With the (?P[.]+) part of the last url line removed, the page will render OK, but the links don't work (as there's no user parameter being passed). With the regex present (not only this one, but the many others I've tried), I get a NoReverseMatch error:
NoReverseMatch at /
Reverse for 'userposts' with no arguments not found. 1 pattern(s) tried: ['posts/userposts/(?P<user>[.]+)']
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.11
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'userposts' with no arguments not found. 1 pattern(s)
tried: ['posts/userposts/(?P<user>[.]+)']
Exception Location: /usr/local/lib/python3.5/dist-
packages/django/urls/resolvers.py in _reverse_with_prefix, line 497
Python Executable: /usr/bin/python3
Python Version: 3.5.2
Python Path:
['/home/darren/redditclone/redditclone',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/home/darren/.local/lib/python3.5/site-packages',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages']
Server time: Thu, 18 May 2017 18:21:11 +0000
Your userposts is defined like
url(r'^userposts/(?P<user>[.]+)', views.userposts, name='userposts')
which means it requires a user argument to resolve.
To pass such an argument, you'd do
{% url 'posts:userposts' user_goes_here %}
Try this instead
{{ post.author.username }}

No CSRF token after Django 1.8 form error

I recently upgraded my website to Django 1.8 and am getting an "ImportError No module named lib" when my signup (user registration) form is posted. Specifically, if a user is signing up for an account and their passwords don't match, my form will display an error. If they then enter matching passwords, I get the following Django error:
Request Method: POST
Request URL: http://localhost:8000/create_account/
Django Version: 1.8.4
Python Version: 2.7.5
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'account',
'home',
'members',
'profile']
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback:
File "/Users/me/venv/scores/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
125. response = middleware_method(request, callback, callback_args, callback_kwargs)
File "/Users/me/venv/scores/lib/python2.7/site-packages/django/middleware/csrf.py" in process_view
189. return self._reject(request, REASON_BAD_TOKEN)
File "/Users/me/venv/scores/lib/python2.7/site-packages/django/middleware/csrf.py" in _reject
101. return _get_failure_view()(request, reason=reason)
File "/Users/me/venv/scores/lib/python2.7/site-packages/django/middleware/csrf.py" in _get_failure_view
33. return get_callable(settings.CSRF_FAILURE_VIEW)
File "/Users/me/venv/scores/lib/python2.7/site-packages/django/utils/lru_cache.py" in wrapper
101. result = user_function(*args, **kwds)
File "/Users/me/venv/scores/lib/python2.7/site-packages/django/core/urlresolvers.py" in get_callable
112. if submod and not module_has_submodule(import_module(parentmod), submod):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
Exception Type: ImportError at /create_account/
Exception Value: No module named lib
As you can see from the stacktrace, when the form is posted with matching passwords, the response is being deemed invalid by the middleware before control is even returned to the create_account view that displayed the form. I set a breakpoint in the urlresolvers.py module and found that the module that can't be found is "lib.local_csrf". I should add that the form itself is composed of both a signin (authentication) form and the signup (registration) form in question and both forms contain csrf_token tags:
# home/templates/home.html
<form action="{% url 'sign-in' %}" method="post">
{% csrf_token %}
<!-- error fields appear here -->
{% for field in sign_in_form.visible_fields %}
{{ field.label_tag }}
{{ field }}
<input type="submit" value="Sign in">
Forgot password?
</form>
<form action="{% url 'create-account' %}" method="post">
{% csrf_token %}
<!-- error fields appear here -->
{% for field in create_account_form.visible_fields %}
{{ field.label_tag }}
{{ field }}
{% endfor %}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
<input type="submit" value="Sign up">
</form>
Here is the create_account view:
# account/views.py
def create_account(request, template):
# Initialize the signin form on the same page.
sign_in_form = SignInAuthenticationForm(request, label_suffix="")
if request.method == "POST":
create_account_form = CreateAccountForm(request.POST, label_suffix="")
if create_account_form.is_valid():
user = User.objects.create_user(
username = create_account_form.cleaned_data['username'],
password = create_account_form.cleaned_data['password1']
)
# Create a new account.
account = Account(user=user)
account.save()
# Do other stuff and then redirect user to next form
else:
create_account_form = CreateAccountForm(label_suffix="")
return render_to_response(template, locals())
What's most interesting is that when I set a breakpoint in the process_view in django.middleware.csrf, the csrf_token and request_csrf_token variables both contain the same value when the user initially submits the form with mismatched passwords. But when they enter matching passwords and resubmit the form a second time, the csrf_token contains the token value but request_csrf_token is blank. This was confirmed by the fact that request.POST['csrfmiddlewaretoken'] is not in the request.POST dictionary when the user resubmits the form. I don't understand why this is happening.
This form worked perfectly well in Django 1.6 but it's stopped working in 1.8 (or possibly 1.7). I looked through the 1.7 and 1.8 release notes and didn't see any changes to the CSRF functionality. I also read the template docs that pertain to CSRF and didn't see anything new there. Doing an online search on this error didn't turn up anything either.
I suspect that some of you will suggest that I use the django-registration-redux library. I don't think I can use it due to my registration workflow. You see, after the user registers on this form, they're redirected first to a page when they enter their user profile, then to a page where they can upload a photo, and then to a page to review and approve their profile and photo. After that, they're forwarded to my payment processor. They're only truly registered with a valid account if my payment processor tells me their payment method has been approved.
Thanks.
The actual error No module named lib appears to be because Django can't import the CSRF_FAILURE_VIEW you have specified in your settings. You could try removing it from your settings, then Django should show the default CSRF failure page instead of the error. I can't tell why the import is failing, because you haven't shown what CSRF_FAILURE_VIEW or your project structure is.
To fix the CSRF error, try using the render shortcut instead of render_to_response. It renders the template with a request context, so that the csrf_token tag works.
# avoid locals() if possible!
return render(request, template, {...})

Trying to send parameters

I'm trying to obtain dedicated urls of some products that I have in my shop.html page. I have five products that I named "cards": (Ysera, Neltharion, Nozdormu, Alexstrasza, Malygos). Each card should have a dedicated url (localhost:8000/card/1/, localhost:8000/card/2/, etc). but instead of obtaining that url, django launch me that message:
DoesNotExist at /card/1/ card matching query does not exist.
I imported properly the class model "card" in my views.py, in fact I am justly using card in a filter function to obtain all products in shop.html. please look my views.py:
from django.shortcuts import render_to_response
from django.template import RequestContext
from dracoin.apps.synopticup.models import card
from dracoin.apps.home.forms import ContactForm,LoginForm
from django.core.mail import EmailMultiAlternatives
from django.contrib.auth import login,logout,authenticate
from django.http import HttpResponseRedirect
def index(request):
return render_to_response('home/index.html',context_instance=RequestContext(request))
def landing(request):
return render_to_response('home/landing.html',context_instance=RequestContext(request))
def shop(request):
tarj = card.objects.filter(status=True)
ctx = {'tarjetas':tarj}
return render_to_response('home/shop.html',ctx,context_instance=RequestContext(request))
def singleCard(request,id_tarj):
tarj = card.objects.get(id=id_tarj)
ctx = {'card':tarj}
return render_to_response('home/singleCard.html',ctx,context_instance=RequestContext(request))
here my urls.py:
url(r'^card/(?P<id_tarj>.*)/$','dracoin.apps.home.views.singleCard',name='vista_single_card'),
My imported model:
class card(models.Model):
nombre = models.CharField(max_length=100)
descripcion = models.TextField(max_length=300)
status = models.BooleanField(default=True)
def __unicode__(self):
return self.nombre
My singleCard.html:
{% extends 'base.html' %}
{% block title %} Tarjeta {{card.nombre}} {% endblock %}
{% block content %}
<h1>{{ card.nombre }}</h1><br>
<p> {{ card.descripcion }}</p>
{% endblock %}
I don't know if I have a wrong refering "card" class. But I try to apply other answers in this forum. For example:
In Django, how do I objects.get, but return None when nothing is found?
matching query does not exist Error in Django
Django error - matching query does not exist
I don't know if I commit a mistake applying these solutions. Including I try:
tarj = card.objects.filter(id=id_tarj)
Using this I obtain a blank page of my website...
apologizeme in advance my extensive question and if I overlook something.
Thanks!!
Answering to wolendranh I have an urls.py by app and the main urls.py.
Recently I'm learning django by my side and I can't understand how I can define my own consistent identifier in this case.
if it is still useful I put here a traceback generated with the error:
Environment:
Request Method: GET
Request URL: http://localhost:8000/card/1/
Django Version: 1.7
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dracoin.apps.synopticup',
'dracoin.apps.home')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/home/draicore/project/multilevel/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/draicore/project/dracoin/dracoin/apps/home/views.py" in singleCard
24. tarj = card.objects.get(id=id_tarj)
File "/home/draicore/project/multilevel/local/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method
92. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/draicore/project/multilevel/local/lib/python2.7/site-packages/django/db/models/query.py" in get
357. self.model._meta.object_name)
Exception Type: DoesNotExist at /card/1/
Exception Value: card matching query does not exist.
excuse me for prolong this question.
As karthikr says in the comment, you don't have a card with id=1.
This is probably because you previously deleted and recreated a card. The id is an autoincrement field, which means the database does not reuse IDs that have been deleted. If you want your item to have a consistent identifier which you can always use to query it in the URL, you should probably define that as an explicit IntegerField (using another name than id), and query against that instead. Even better, use a slug rather than a numeric ID.
I have few things to clarify:
1. Do you have a single urls.py file in your project? or separate for every app.
If you have a separate like "your_project/card/urls" and it is included into main urls.py you should NOT use "card/" in your url. Because Django already knows that request is for that app.
r'^card/(?P<id_tarj>.*)/$' -> r'^(?P<id_tarj>.*)/$'
If it is in main urls.py try to replace:
r'^card/(?P<id_tarj>.*)/$'
to
r'^card/(?P\d+))/$'
P.s.: I don't have anough reputation for comments, so I added an answer. Sorry.

Using #csrf_exempt and creating a CSRF token in the same view

I am expecting a POST from a 3rd party server. I understand that I need to use the #csrf_exempt decorator to allow for a post from a 3rd party server. I'm using Django 1.4 and Python 2.7 on Ubuntu 12.04.
Now, my view is going to generate an un-bound form that will contain fields for a user to populate as well as hidden fields containing information from the original POST. So, the first POST will initiate a second POST.
The second POST is going to be sent from my server to another view on my server. I'm trying to figure out how to generate a CSRF token for my form.
I'm trying to do exactly what I've read in the documentation.
My code from views.py:
from django.core.context_processors import csrf
from django.shortcuts import render_to_response
from gateway_interface.post_handling import PostHandling
#csrf_exempt
def requestNewPaymentInfo(request):
c = {}
c.update(csrf(request))
# Gather information posted
if (request.method == "POST"):
# Create the initialization dictionary based on POST values
postHandling = PostHandling()
post_dict = postHandling.createDictionary(request)
# Create the form
form = addPaymentForm(initial = post_dict)
return render_to_response('requestNewPaymentInfo.html', { 'form' : form }, c)
What do you do on the template side now?!? Again, from the documentation I thought I should do the following:
<form action="/addPayment/" method="post">
{% csrf_token %}
</form>
I test this by doing a POST from a 3rd party server. Sometimes I see the form fully generated with what appears to be a valid CSRF token.
Sometimes I see a failure that looks like this:
Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'gateway_interface')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py" in wrapped_view
77. return view_func(*args, **kwargs)
File "/home/tokeniz/tokeniz/gateway_interface/views.py" in requestNewPaymentInfo
64. return render_to_response('requestNewPaymentInfo.html', { 'form' : form }, c)
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts/__init__.py" in render_to_response
20. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in render_to_string
178. context_instance.pop()
Exception Type: TypeError at /requestNewPaymentInfo/
Exception Value: pop expected at least 1 arguments, got 0
Then I will eventually get this error:
Forbidden (403)
CSRF verification failed. Request aborted.
Once I receive the CSRF verification failed error I will continue to get this error until I clear the cookies and start over.
Can anyone tell me what I'm doing wrong? I can see it has something to do with how I generate the CSRF token. I don't understand how the process works based on what is in the documentation. What is c in my view? An empty dictionary that I'm populating with information and passing to render_to_response. Ok, but how is that being used in the template?
Should my template have something like this:
<form action="/addPayment/" method="post">
{% c.csrf_token %}
</form>
If not, why? How does Django know that this c contains the CSRF token?
Any help would be greatly appreciated.
To fix your problem, let me can clarify some things.
Django's template system in a nutshell works with two pieces of data: context and template.
When you put a variable to display in your template file, like {{ foo }}, django is going to look inside corresponding context instance, which a dict on steroids, to find the value of that variable.
Now to render_to_response, what you pass to it as a second parameter, a dict, is essentially the data you want to put in template's context, and so it will be available for you. The third paramater is a Context instance, not the data itself, it can be useful when you need to customize things.
Ok, so let's look at your example,
return render_to_response('requestNewPaymentInfo.html', { 'form' : form }, c)
Here, you made a mistake reading docs example, you put c as a context instance, not context data, hence your token didn't even make it to the template, and you got all those weird errors where django was expecting Context object, but only got dict.
So to fix, you just need to pass csrf token inside template data:
c.update({'form': form})
return render_to_response('requestNewPaymentInfo.html', c)
And inside the template:
{% csrf_token %}
I would suggest reading template system explanation for programmers, it is very well written.