Django 1.9: 'AnonymousUser' object is not iterable - django

I was working on a Django 1.9 project, and suddenly this error popped up when I attempted to view my site's home page as a logged-out user.
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.9.7
Python Version: 2.7.10
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sites',
'django.contrib.staticfiles',
'captcha',
'debug_toolbar',
'django_extensions',
'djstripe',
'crm',
'launch',
'rentals',
'widget_tweaks']
Installed Middleware:
[u'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'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 "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
174. response = self.process_exception_by_middleware(e, request)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
172. response = response.render()
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/template/response.py" in render
160. self.content = self.rendered_content
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/template/response.py" in rendered_content
137. content = template.render(context, self._request)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/template/backends/django.py" in render
95. return self.template.render(context)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/template/base.py" in render
204. with context.bind_template(self):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py" in __enter__
17. return self.gen.next()
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/debug_toolbar/panels/templates/panel.py" in _request_context_bind_template
79. context = processor(self.request)
File "/Users/me/projects/rentalguru/src/rentals/processors.py" in allCategories
4. expense_categories = ExpenseCategory.objects.filter(user=request.user)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method
122. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/query.py" in filter
790. return self._filter_or_exclude(False, *args, **kwargs)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/query.py" in _filter_or_exclude
808. clone.query.add_q(Q(*args, **kwargs))
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/sql/query.py" in add_q
1243. clause, _ = self._add_q(q_object, self.used_aliases)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/sql/query.py" in _add_q
1269. allow_joins=allow_joins, split_subq=split_subq,
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/sql/query.py" in build_filter
1174. self.check_related_objects(field, value, opts)
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/db/models/sql/query.py" in check_related_objects
1073. for v in value:
File "/Users/me/projects/rentalguru/lib/python2.7/site-packages/django/utils/functional.py" in inner
205. return func(self._wrapped, *args)
Exception Type: TypeError at /
Exception Value: 'AnonymousUser' object is not iterable
I'm not sure what would be causing this, and there's only one Google search result (for this site) for this error. I searched the code for the is_authenticated() method and didn't find anything, so I'm unsure where to turn. Working through the stack trace didn't show any useful (for me) information.
Here is my view:
class HomePageView(TemplateView):
template_name = 'home.html'
No login decorators or wrapped functions that I can tell.
Let me know if I need to post anything else.
EDIT: Asked for the model, here is the offending context processor instead:
def allCategories(request):
expense_categories = ExpenseCategory.objects.filter(user=request.user)
tags = {'categories': expense_categories}
return tags

I just stumbled myself upon this error. Thankfully the answer was provided in the comments:
As you said you tried to view home page with logged out user and this ExpenseCategory.objects.filter(user=request.user) filtering of Anonymous user (because you are logged out now) seems to be the culprit. Either you should allow only a authenticated user to this view or handle the case where your user is Anonymous
As for myself, I had a view, where I was filtering on a model based on the current user, which apparantly fails, when the user is the AnonymousUser.
I fixed this by adding a check:
if request.user.is_active:
expense_categories = ExpenseCategory.objects.filter(user=request.user)
Note that some people seem to prefer to check request.user.is_authenticated instead.
If you are dealing with a view that shall be accessed by logged in users only, you can also use the #login_required decorator.
For reference:
https://docs.djangoproject.com/en/1.11/ref/contrib/auth/#django.contrib.auth.models.User.is_active
https://docs.djangoproject.com/en/1.11/ref/contrib/auth/#django.contrib.auth.models.User.is_authenticated
https://docs.djangoproject.com/en/1.11/topics/auth/default/#django.contrib.auth.decorators.login_required

Related

user_change_password() got an unexpected keyword argument 'extra_context'

Django 3.0.7
When I try to change password in admin site, I get
TypeError at /admin/auth/user/1/password/
user_change_password() got an unexpected keyword argument 'extra_context'
Namely I pressed "this form" link:
More details
Environment:
Request Method: GET
Request URL: http://localhost:8000/admin/auth/user/1/password/
Django Version: 3.0.7
Python Version: 3.8.0
Installed Applications:
['admin_aux',
'images.apps.ImagesConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'posts',
'sidebars',
'general',
'categories',
'marketing',
'home',
'authors',
'taggit',
'cachalot',
'django_cleanup.apps.CleanupConfig',
'widgets',
'code_samples',
'hyper_links',
'polls',
'applications',
'videos',
'quotations',
'languages',
'people',
'arbitrary_htmls.apps.ArbitraryHtmlsConfig']
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 (most recent call last):
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/contrib/admin/sites.py", line 231, in inner
return view(request, *args, **kwargs)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/home/michael/PycharmProjects/pcask/venv/lib/python3.8/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
Exception Type: TypeError at /admin/auth/user/1/password/
Exception Value: user_change_password() got an unexpected keyword argument 'extra_context'
How can I localize this problem?
What's happening...
I have no idea tbh. It is worth noting a few things though, that the url, should call a method in the User Auth ModelAdmin at django/contrib/auth/admin called user_change_password. It has the following signature:
def user_change_password(self, request, id, form_url=""):
which is why the error is being raised, because somehow extra_context is being passed to it.
There is also a way for you to change the logged on users password, which does accept a extra_context kwarg. My best guess is that one of the apps has overwritten the standard auth ModelAdmin and done it not quite right. Certainly everything works fine with a fresh django 3.0.7 project.
How can I localize this problem?
I would remove all of your additional apps. Hopefully this will fix the problem. If it doesn't then this becomes more interesting. But if it does, I would add them back in one by one until it breaks, and then you'll figure out which additional app is breaking things.
maybe you even can help me cope with it.
There's a few things I can think of that you could do if you just want to change the password. You can change user details via the shell:
python manage.py shell
Then the following will enable you to change a password:
from auth.models import User
user = User.objects.get(id=1) # Or whatever user you want
user.set_password('my_new_password')
user.save()
This should do the trick. Even easier still, there is a management command that does it (but for this you will need to know the current password). You can simply run:
manage.py changepassword *username*
I had this issue (though in Django 2.2). It started after I took the advice from another Stack Overflow post on adding extra_context to every admin page. This seems harmless, but breaks the "change password" form. In the end I deleted the 'extra_context' changes to urls.py and added the extra_context ONLY to the admin forms I needed using the ModelAdmin add_view and change_view methods.
# New Layer Form
def add_view(self, request, form_url='', extra_context={}):
extra_context['CATALOG_TECHNOLOGY'] = settings.CATALOG_TECHNOLOGY
return super(LayerAdmin, self).add_view(request, form_url, extra_context)
# Edit Layer Form
def change_view(self, request, object_id, extra_context={}):
extra_context['CATALOG_TECHNOLOGY'] = settings.CATALOG_TECHNOLOGY
return super(LayerAdmin, self).change_view(request, object_id, extra_context=extra_context)
Here are the commits for full context:
Breaking Commit
urls.py
Fixing Commits
urls.py
admin.py

Django-notification invalid literal for int() with base 10

I'm using django-notification to create notifications. based on it's documention I putted:
url(r'^inbox/notifications/', include(notifications.urls, namespace='notifications')),
in my urls.py. I generate a notification for test by using this in my views.py:
guy = User.objects.get(username = 'SirSaleh')
notify.send(sender=User, recipient=guy, verb='you visted the site!')
and I can easily get the number of unread notification in this url:
http://127.0.0.1:8000/inbox/notifications/api/unread_count/
it return {"unread_count": 1} as I want. but with /api/unread_list/ I can not to get the list of notifications and I get this error:
ValueError at /inbox/notifications/
invalid literal for int() with base 10: '<property object at 0x7fe1b56b6e08>'
As I beginner in using django-notifications any help will be appreciated.
Full TraceBack
Environment:
Request Method: GET Request URL:
http://127.0.0.1:8000/inbox/notifications/api/unread_list/
Django Version: 2.0.2 Python Version: 3.5.2 Installed Applications:
['django.contrib.admin', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.staticfiles',
'django.contrib.sites', 'django.forms', 'rest_framework',
'allauth', 'allauth.account', 'allauth.socialaccount', 'guardian',
'axes', 'django_otp', 'django_otp.plugins.otp_static',
'django_otp.plugins.otp_totp', 'two_factor', 'invitations',
'avatar', 'imagekit', 'import_export', 'djmoney', 'captcha',
'dal', 'dal_select2', 'widget_tweaks', 'braces', 'django_tables2',
'phonenumber_field', 'hitcount', 'el_pagination',
'maintenance_mode', 'notifications', 'mathfilters',
'myproject_web', 'Order', 'PhotoGallery', 'Search', 'Social',
'UserAccount', 'UserAuthentication', 'UserAuthorization',
'UserProfile'] Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_otp.middleware.OTPMiddleware',
'maintenance_mode.middleware.MaintenanceModeMiddleware']
Traceback:
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/core/handlers/exception.py"
in inner
35. response = get_response(request)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/core/handlers/base.py"
in _get_response
128. response = self.process_exception_by_middleware(e, request)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/core/handlers/base.py"
in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/notifications/views.py"
in live_unread_notification_list
164. if n.actor:
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/contrib/contenttypes/fields.py"
in get
253. rel_obj = ct.get_object_for_this_type(pk=pk_val)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/contrib/contenttypes/models.py"
in get_object_for_this_type
169. return self.model_class()._base_manager.using(self._state.db).get(**kwargs)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/query.py"
in get
394. clone = self.filter(*args, **kwargs)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/query.py"
in filter
836. return self._filter_or_exclude(False, *args, **kwargs)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/query.py"
in _filter_or_exclude
854. clone.query.add_q(Q(*args, **kwargs))
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/sql/query.py"
in add_q
1253. clause, _ = self._add_q(q_object, self.used_aliases)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/sql/query.py"
in _add_q
1277. split_subq=split_subq,
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/sql/query.py"
in build_filter
1215. condition = self.build_lookup(lookups, col, value)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/sql/query.py"
in build_lookup
1085. lookup = lookup_class(lhs, rhs)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/lookups.py"
in init
18. self.rhs = self.get_prep_lookup()
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/lookups.py"
in get_prep_lookup
68. return self.lhs.output_field.get_prep_value(self.rhs)
File
"/home/saleh/Projects/myproject_web/lib/python3.5/site-packages/django/db/models/fields/init.py"
in get_prep_value
947. return int(value)
Exception Type: ValueError at /inbox/notifications/api/unread_list/
Exception Value: invalid literal for int() with base 10: ''
The actor_object_id needs to be a CharField to support UUID based primary keys.
oops! It was my mistake.
I Finally find out what was the problem. actor_object_id was the field of notifications_notification table, which User.objects.get(username = 'SirSaleh') saved in it. It should be Interger (user_id of actor).
So I dropped previous table changed instance to User.objects.get(username = 'SirSaleh') to User ID. Problem solved.
So Why type of actor_object_id is CharField (varchar)? (at least I don't know) ;))
This is old, but I happen to know the answer.
In your code, you wrote:
guy = User.objects.get(username = 'SirSaleh')
notify.send(sender=User, recipient=guy, verb='you visted the site!')
You express that you want guy to be your sender However, in notify.send, you marked the sender as a generic User object, not guy.
So, change your code to:
guy = User.objects.get(username = 'SirSaleh')
notify.send(sender=guy, recipient=guy, verb='you visted the site!')
Notifications will take the user object guy, extrapolate the ID and store it in the database accordingly.

Django REST framework IntegerField max_length issue

I am getting an "__init__() got an unexpected keyword argument 'max_length'" error for my model field of IntegerField with max_length. The stack trace is as follows:
Environment:
Request Method: GET
Request URL: http://localhost:8000/api/jmc/foundation/
Django Version: 1.7.1
Python Version: 2.7.8
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dajaxice',
'dajax',
'rest_framework',
'core',
'analytics',
'api')
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 "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py" in wrapped_view
57. return view_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py" in dispatch
406. response = self.handle_exception(exc)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py" in dispatch
403. response = handler(request, *args, **kwargs)
File "/home/dev/Documents/Program Codes/Python/Django/Hera/api/views.py" in get
17. return Response(serializer.data)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/serializers.py" in data
547. ret = super(ListSerializer, self).data
File "/usr/local/lib/python2.7/dist-packages/rest_framework/serializers.py" in data
174. self._data = self.to_representation(self.instance)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/serializers.py" in to_representation
500. self.child.to_representation(item) for item in iterable
File "/usr/local/lib/python2.7/dist-packages/rest_framework/serializers.py" in to_representation
382. fields = [field for field in self.fields.values() if not field.write_only]
File "/usr/local/lib/python2.7/dist-packages/rest_framework/serializers.py" in fields
245. for key, value in self.get_fields().items():
File "/usr/local/lib/python2.7/dist-packages/rest_framework/serializers.py" in get_fields
911. ret[field_name] = field_cls(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/fields.py" in __init__
597. super(IntegerField, self).__init__(**kwargs)
Exception Type: TypeError at /api/jmc/foundation/
Exception Value: __init__() got an unexpected keyword argument 'max_length'
You might want to use the MaxValueValidator with IntegerField instead of max_length.
from django.db import models
from django.core.validators import MaxValueValidator
class MyModel(models.Model):
number = models.IntegerField(validators=[MaxValueValidator(100)])
Looks like IntegerField in Django doesn't have an max_length option. The reason we don't get any error is because Django suppresses it and 'Django REST framework' doesn't. Just removing the max_length option will make it work again.
Contrary to popular belief and common sense, Django does support the max_length argument on the IntegerField as well as any other field. The error you are seeing here is a known issue with Django REST Framework that does not currently have a fix.
The easiest way to fix this in your serializers (until a fix is done in DRF) is to redefine the field on the serializer without the max_length argument.
class MySerializer(serializers.ModelSerializer):
int_field = serializers.IntegerField()

Not able to create user profile using django-registration

I am using django-registration app. I am trying to create a social networking website. I am a newbie to website development. Here is the error I am getting:
Environment:
Request Method: POST
Request URL: 127.0.0.1:8000/accounts/register/
Django Version: 1.4.2
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'registration_defaults',
'django.contrib.admin',
'registration',
'polls')
Installed Middleware:
('django.middleware.csrf.CsrfViewMiddleware',
'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 "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/registration/views.py" in register
187. new_user = backend.register(request, **form.cleaned_data)
File "/Library/Python/2.7/site-packages/registration/backends/default/__init__.py" in register
79. password, site)
File "/Library/Python/2.7/site-packages/django/db/transaction.py" in inner
209. return func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/registration/models.py" in create_inactive_user
78. new_user = User.objects.create_user(username, email, password)
File "/Library/Python/2.7/site-packages/django/contrib/auth/models.py" in create_user
160. user.save(using=self._db)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save
463. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save_base
565. created=(not record_exists), raw=raw, using=using)
File "/Library/Python/2.7/site-packages/django/dispatch/dispatcher.py" in send
172. response = receiver(signal=self, sender=sender, **named)
File "/Users/dineshsingh/Desktop/django/mysite/users/models.py" in create_user_profile
20. UserProfile.objects.create(user=instance)
File "/Library/Python/2.7/site-packages/django/db/models/manager.py" in create
137. return self.get_query_set().create(**kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in create
377. obj.save(force_insert=True, using=self.db)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save
463. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save_base
551. result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/Library/Python/2.7/site-packages/django/db/models/manager.py" in _insert
203. return insert_query(self.model, objs, fields, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in insert_query
1593. return query.get_compiler(using=using).execute_sql(return_id)
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
910. cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py" in execute
40. return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
344. return Database.Cursor.execute(self, query, params)
Exception Type: DatabaseError at /accounts/register/
Exception Value: no such table: users_userprofile
Any help will be highly appreciated.
According to the Error stack, I think you are doing it in the wrong manner.
It may be that you are creating an app named `users` which is not required here.
Here is the step by step process how to use django-registration.
After installing django-registration we need to add it in the settings.py file to make sure that our django engine reads it and loads it.
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'registration', #<--Here I have added
)
Now You need to add a few more settings in the settngs.py file:
ACCOUNT_ACTIVATION_DAYS = 2
EMAIL_HOST = 'localhost'
DEFAULT_FROM_EMAIL = 'webmaster#localhost'
LOGIN_REDIRECT_URL = '/'
Now update the urls.py file to send all the /accounts/ request to the django-registration app.
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
...
(r'^accounts/', include('registration.urls')),
...
)
Now you need to create some templates to support your django-registration.
login.html — user login form
logout.html — shown after a user has logged out
password_change_form.html — password change form
password_change_done.html — shown after successful password change
password_reset_form.html — ask user for email to send password-reset mail to
password_reset_email.html — template for password-reset mail
password_reset_done.html — shown after password-reset email has been sent
password_reset_confirm.html — ask user for new password after reset
password_reset_complete.html — shown after successful password reset
registration_form.html — user registration form
registration_complete.html — shown after a user has registered
activation_email_subject.txt — subject of activation email
activation_email.txt — template for activation email
activate.html — shown after a user has activated his account
A basic model that what you need to put in these files can be #the-django-registration-git-hub-link
Now I hope you can get it running.
Few more link to check out.
Link 1
Link 2
Do you have right AUTH_PROFILE_MODULE in your settings.py?
That seems it should be:
AUTH_PROFILE_MODULE = 'registration.RegistrationProfile'

Some cache problems

I'm wondering if I can delete a cached content made in template cache. I want to delete it from my view. I have in my template {% cache 500 cache_name sites.number %}
Is it possible to delete all "cache_name" cached content within the view, for example when some action is made?
I want to use per-vie cache. I do all what is described, but when I call: #cache_page(3600, cache="cache_name") I get error:
Exception Type: ValueError Exception
Value: need more than 1 value to
unpack
(Below is the traceback)
What I want to achieve is to cache all my template block or view and have a possibility to delete all cache connected with it when some actions are made. Pagination is included
Traceback:
Environment:
Request Method: GET
Request URL: http://localhost:8000/portfolio/
Django Version: 1.3 beta 1 SVN-15661
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'apps.index']
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 "E:\Python\django\core\handlers\base.py" in get_response
101. request.path_info)
File "E:\Python\django\core\urlresolvers.py" in resolve
252. sub_match = pattern.resolve(new_path)
File "E:\Python\django\core\urlresolvers.py" in resolve
252. sub_match = pattern.resolve(new_path)
File "E:\Python\django\core\urlresolvers.py" in resolve
158. return ResolverMatch(self.callback, args, kwargs, self.name)
File "E:\Python\django\core\urlresolvers.py" in _get_callback
164. self._callback = get_callable(self._callback_str)
File "E:\Python\django\utils\functional.py" in wrapper
124. result = func(*args)
File "E:\Python\django\core\urlresolvers.py" in get_callable
91. lookup_view = getattr(import_module(mod_name), func_name)
File "E:\Python\django\utils\importlib.py" in import_module
35. __import__(name)
File "E:\Python\apps\index\views.py" in <module>
29. #cache_page(600, cache='my_cache')
File "E:\Python\django\views\decorators\cache.py" in cache_page
58. return decorator_from_middleware_with_args(CacheMiddleware)(cache_timeout=args[0], cache_alias=cache_alias, key_prefix=key_prefix)
File "E:\Python\django\utils\decorators.py" in _make_decorator
81. middleware = middleware_class(*m_args, **m_kwargs)
File "E:\Python\django\middleware\cache.py" in __init__
204. self.cache = get_cache(self.cache_alias, **cache_kwargs)
File "E:\Python\django\core\cache\__init__.py" in get_cache
173. backend, location, params = parse_backend_conf(backend, **kwargs)
File "E:\Python\django\core\cache\__init__.py" in parse_backend_conf
131. mod_path, cls_name = backend.rsplit('.', 1)
Exception Type: ValueError at /portfolio/
Exception Value: need more than 1 value to unpack
What version of Django are you using? The parameter "cache" is only available in the development version. If you're using Django 1.2, you can only use "key_prefix".
http://docs.djangoproject.com/en/1.2/topics/cache/
The cache middleware caches every page
that doesn't have GET or POST
parameters.