username = user_form.cleaned_data['username']
if commit:
user.save()
return user
if commit:
user.save()
return user
from registration.backends.default.views import RegistrationView
а не from registration.views import RegistrationView
ACCOUNT_USER_DISPLAY (=a callable returning user.username)
A callable (or string of the form 'some.module.callable_name') that takes a user as its only argument and returns the display name of the user. The default implementation returns user.username.
ACCOUNT_USER_DISPLAY = lambda user: u'%s %s' % (user.first_name, user.last_name)
илиACCOUNT_USER_DISPLAY = lambda user: user.get_full_name()
илиACCOUNT_USER_DISPLAY = 'myapp.somemodule.utils.user_display'
def authenticate(username=None, password=None, **kwargs):
from django.contrib.auth import get_user_model
UserModel = get_user_model()
if username is None:
username = kwargs.get(UserModel.USERNAME_FIELD)
try:
user = UserModel._default_manager.get_by_natural_key(username)
if user.check_password(password):
return user
except UserModel.DoesNotExist:
# Run the default password hasher once to reduce the timing
# difference between an existing and a non-existing user (#20760).
UserModel().set_password(password)
You may need to add u'www.cirk.irk.ru' to ALLOWED_HOSTS
def base_context(func):
def wrapped(*args, **kwargs):
context_dict = {'categories_menu': Category.objects.filter(menu=True)}
kwargs['context_dict'] = context_dict
return func(*args, **kwargs)
return wrapped
@base_context
def index(request, **kwargs):
page_list_new = Page.objects.order_by('-datetime')[:5]
context_dict = kwargs.get('context_dict', {})
context_dict['pages_new'] = page_list_new
return render(request, 'home/index.html', context_dict)
l1 = [
{'id': 1,'count': 5},
{'id': 2,'count': 8},
{'id': 3,'count': 11}
]
l2 = [
{'id': 1,'name': 'Alex'},
{'id': 2,'name': 'Jack'},
{'id': 3,'name': 'Peter'}
]
l3 = {x['id']: x['name'] for x in l2}
for x in l1:
if x['id'] in l3:
x.update({'name': l3[x['id']]})
print(l1) # в l1 результат