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, {...})
Related
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!
I have been developing a site using Django and am trying to implement a simple form, based off of one of the models inside my app. I have a few issues with getting it to work, but my current major problem is that I keep receiving the following error: CSRF token missing or incorrect.
I am running Django 1.6 with python 2.7.
I have already looked over the following posts to try fix my problem (and various other solutions to which I give contextual reference to where appropriate), but it has not worked for me:
Django: CSRF token missing or incorrect - Basically, passing RequestContext along with my render_to_response return.
CSRF Token missing or incorrect - I have made sure that django.middleware.csrf.CsrfViewMiddleware appears in my settings.py file and I have tried to add the django.core.context_processors.csrf as instructed to my TEMPLATE_CONTEXT_PROCESSORS setting but there is no change. When I check these settings in the shell, I get the following output:
> from django.conf import settings
> settings.TEMPLATE_CONTEXT_PROCESSORS
('django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug', 'django.core.context_processors.i18n',
'django.core.context_processors.media', 'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages')
I placed the following code in my settings.py file but I continue to get the 403 CSRF token error:
import django.conf.global_settings as DEFAULT_SETTINGS
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
'django.core.context_processors.csrf',
)
I have also followed the suggestions given in the error message itself, i.e. makign sure I have the {% csrf_token %} tags in place, using RequestContext instead of Context.
from my views.py file:
from django.shortcuts import render
from django.views.decorators.csrf import csrf_protect, csrf_exempt
from django.template import loader, Context
from django.http import HttpResponse
from forms import StudentForm
from django.http import HttpResponseRedirect
from django.core.context_processors import csrf
from django.template import RequestContext
def edit(request):
form = StudentForm(request.POST or None)
if form.is_valid():
form.save()
return Redirect('/myprofile/')
return render(request, 'myprofile.html',{'form':form})
Please not that I have read several other guides to fixing this problem that involve including RequestContext in several different ways: return render_to_response('myprofile.html', RequestContext(request, {})) and return render_to_response('myprofile.html', RequestContext(request)), none of which worked for me.
my settings.py file:
import django.conf.global_settings as DEFAULT_SETTINGS
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myprofile',
)
MIDDLEWARE_CLASSES = (
'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',
)
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
'django.core.context_processors.csrf',
)
My html code is as follows:
<form action = "/myprofile/" method = "post"> {% csrf_token %}
<ul>
{{ form.as_ul }}
</ul>
<input type = "submit" name = "Submit" value = "Edit Form">
</form>
Please not that I have also attempted to add the token as a hidden input, but this has not solved my issue. The function that generates this view is also the same function that is referred to by the form's action, <form action = "/myprofile/" ...>.
Any assistance with this issue would be greatly appreciated.
Your problem is here:
return render_to_response('myprofile.html',{},RequestContext(request))
Although you have added the csrf:
c = {}
c.update(csrf(request))
You don't do anything with c. To solve this once and for all, just use the render shortcut:
from django.shortcuts import render, redirect
def edit(request):
form = StudentForm(request.POST or None)
if form.is_valid():
form.save()
return redirect('/myprofile/')
return render(request, 'myprofile.html', {'form': form})
Next, in your template, you only use {% csrf_token %} not both it and {{ csrf_token }}. The tag will render the form field.
{{ csrf_token }} seems to be empty and overrides the hidden input field which is generated by {% csrf_token %}. just remove the hidden input field with {{ csrf_token }} from your template and it should work probably.
Also, as you are using RequestContext you don't have to add the CSRF token manually to the template, so you can remove following code from your view.
c = {}
c.update(csrf(request))
See https://docs.djangoproject.com/en/1.6/ref/contrib/csrf/#how-csrf-works for more information.
I am developing a web application using Django 1.6 where I require users to log in using my login form. I want to write a test case that tests the procedure of a user logging in.
I did succeed to get a working login page, meaning I was able to log in. The following steps explain my setup. Writing a test case for this procedure did however fail. At this point I'm neither able to spot an error in my test, nor sure whether this approach makes sense before all. Can someone help me?
Update: In the meantime I have noticed, that my form error message was too unspecific. The issue appears to be caused by empty form fields that fail some form validation step. When I add the errors {{ form.errors }} to the template, the response contains the following (formatted a little less nicely):
<ul class="errorlist">
<li>username
<ul class="errorlist">
<li>This field is required.</li>
</ul>
</li>
<li>password
<ul class="errorlist">
<li>This field is required.</li>
</ul>
</li>
</ul>
I'm still not sure how to test this procedure most reasonably. I'm quite new to Django and the philosophy of it's testing framework. May it be, that this issue falls not directly into the scope of the Django testing framework, where models, and views, and forms are (seemingly) intended to be tested rather seperated from each other? Does this test rather fall into the realm of an independent test suite doing black-box/functional testing, e.g., using Selenium?
I started like this:
Started a fresh project, like this:
django-admin.py startproject login_test
added an entry to the login_test/urls.py, like this:
urlpatterns = patterns('',
url(r'^login/$', 'django.contrib.auth.views.login'),
url(r'^admin/', include(admin.site.urls)),
)
made up a template at /home/moooeeeep/login_test/templates/registration/login.html, like this:
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
{% if not user.is_active %}
<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
<input type="hidden" name="next" value="{% url 'django.contrib.auth.views.login' %}" />
</form>
{% else %}
<p>You are logged in as <strong>{{ user.username }}</strong>.</p>
{% endif %}
added the template directory to the TEMPLATE_DIRS in the login_test/settings.py, like this:
TEMPLATE_DIRS = (
'/home/moooeeeep/login_test/templates/',
)
Sync'ed the database to get the auth-related tables, and added a superuser like this:
python manage.py syncdb
If I did not miss a step, at this point I am able to log into my site. When logged in I get displayed my username, if not I see the form, if login fails it displays an error message in addition.
My test case however, after submitting correct post data, gets to see the failed login response, with the user not being logged in.
Here's my login_test/tests.py:
from django.contrib.auth.models import User
from django.contrib.auth import SESSION_KEY
from django.test import TestCase
class LogInTest(TestCase):
def setUp(self):
self.credentials = {
'username': 'testuser',
'password': 'secret'}
User.objects.create_user(**self.credentials)
def test_login(self):
# login
response = self.client.post('/login/', **self.credentials)
# should be logged in now, fails however
self.assertTrue(response.context['user'].is_active)
Here's the output:
$ python manage.py test
Creating test database for alias 'default'...
F
======================================================================
FAIL: test_login (login_test.tests.LogInTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/moooeeeep/login_test/login_test/tests.py", line 16, in test_login
self.assertTrue(response.context['user'].is_active)
AssertionError: False is not true
----------------------------------------------------------------------
Ran 1 test in 0.008s
FAILED (failures=1)
Destroying test database for alias 'default'...
Here's my login_test/settings.py:
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '+6e-6t8dnl$75fx%=7y$+4ipo&i=kvw(p*963p37)7o$1-)30u'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'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',
)
ROOT_URLCONF = 'login_test.urls'
WSGI_APPLICATION = 'login_test.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
TEMPLATE_DIRS = (
'/home/moooeeeep/login_test/templates/',
)
I found out that my passing of the post parameters was wrong (the dictionary must not be unpacked). I also needed to learn, that I needed to follow the redirect issued by the post request after sending the data. Then my login test worked (although the page that was target of the redirection does not exist yet).
Here's my updated test case:
from django.contrib.auth.models import User
from django.test import TestCase
class LogInTest(TestCase):
def setUp(self):
self.credentials = {
'username': 'testuser',
'password': 'secret'}
User.objects.create_user(**self.credentials)
def test_login(self):
# send login data
response = self.client.post('/login/', self.credentials, follow=True)
# should be logged in now
self.assertTrue(response.context['user'].is_active)
Here's the output:
$ python manage.py test
Creating test database for alias 'default'...
.
----------------------------------------------------------------------
Ran 1 test in 0.196s
OK
Destroying test database for alias 'default'...
You don't want to be checking "is_active" boolean, you want to be checking
response.context['user'].is_authenticated
see:
https://docs.djangoproject.com/en/dev/topics/auth/default/#authentication-in-web-requests
and:
https://docs.djangoproject.com/en/dev/ref/contrib/auth/
In my view, I can print request.user.username, however in the template, {{request.user.username}} does not appear. To make this easy, I removed the logic from the function, and I am importing render_to_response & RequestContext.
from django.shortcuts import render_to_response
from django.template import RequestContext
#login_required
#csrf_protect
def form(request):
print request.user.username
data = {}
return render_to_response('form.html', data, context_instance=RequestContext(request))
My guess is that I have problem with my settings.py.
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'src',
)
Thanks in advance for your help-
As mentioned in the documentation, authenticated user's object is stored within user variable in templates. Mentioned documentation includes the following example:
When rendering a template RequestContext, the currently logged-in user, either a User instance or an AnonymousUser instance, is stored in the template variable {{ user }}:
{% if user.is_authenticated %}
<p>Welcome, {{ user.get_username }}. Thanks for logging in.</p>
{% else %}
<p>Welcome, new user. Please log in.</p>
{% endif %}
EDIT: Thanks to #buffer, who dug out this old answer, I have updated it with most recent state. When it was originally written, in less than a month after Django 1.4 (which was released at the end of March 2012), it was correct. But since Django 1.5, proper method to get username is to call get_username() on user model instance. This has been added due to ability to swap User class (and have custom field as username).
Check out the documentation for RequestContext and TEMPLATE_CONTEXT_PROCESSORS.
If you want request to be in your template context, then you need to include django.core.context_processors.request in your TEMPLATE_CONTEXT_PROCESSORS setting. It is not there by default.
However as Tadeck pointed out in his answer user is already available if you are using the default settings, since django.contrib.auth.context_processors.auth is part of the default list for TEMPLATE_CONTEXT_PROCESSORS.
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):