django-contrib


django default Authenticaiton form shows username rather than email

試著忘記壹切 提交于 2020-01-16 09:48:06
问题 I implemented my own user login form with django like below from django.contrib.auth.forms import AuthenticationForm class CustomUserLoginForm(AuthenticationForm): class Meta: model = CustomUser fields = ('email', 'password') then as a view this is what I have: from rest_auth.views import LoginView from users.forms import CustomUserLoginForm class CustomLoginView(LoginView): def get(self, request): form = CustomUserLoginForm() return render(request, "api/test_template.html", context={"form":

Django comments framework

痞子三分冷 提交于 2020-01-06 15:19:11
问题 Hi I am quite new to Django and am trying to get to grips with a few things. I would like to know if the comments framework that is bundled with django can redirect to the refering page if the comment form contains errors? Also if I were to make a rating framework how would I go about achieving this functionality. Would I simply pass the refering url inside my rating form? Thanks for any help Mark 回答1: As someone who dealt with the first issue, I can say I could not find a way, at least

Using Django Cache Middleware causes contrib.auth unit tests to fail

爱⌒轻易说出口 提交于 2020-01-01 18:55:36
问题 Problem: When I add UpdateCacheMiddleware and FetchFromCacheMiddleware to my Django project, I get unittest failures. This is regardless of the CACHE_BACKEND I use (right now I am using locmem://, but the errors are the same when I use file:///path_to_cache) My Middleware: MIDDLEWARE_CLASSES = ( 'django.middleware.cache.UpdateCacheMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',

contrib.staticfiles and Django admin media

你。 提交于 2020-01-01 08:54:13
问题 I just switched from 1.2 to trunk (r15175 at this writing) to play with contrib.staticfiles , and now when using the local devserver all my admin media returns a 404. The static media (as managed by the new contrib app) all work as expected, but I'd like to be able to use the admin with the dev server so that I don't have to restart a local apache instance when dev code changes. Is this known behaviour? I haven't gotten a response in IRC. edit: Seems related to: Admin media disappear while

contrib.staticfiles and Django admin media

假装没事ソ 提交于 2020-01-01 08:54:08
问题 I just switched from 1.2 to trunk (r15175 at this writing) to play with contrib.staticfiles , and now when using the local devserver all my admin media returns a 404. The static media (as managed by the new contrib app) all work as expected, but I'd like to be able to use the admin with the dev server so that I don't have to restart a local apache instance when dev code changes. Is this known behaviour? I haven't gotten a response in IRC. edit: Seems related to: Admin media disappear while

Does Django ship with the authentication templates for use with the django.contrib.auth module? [duplicate]

浪子不回头ぞ 提交于 2019-12-18 05:55:46
问题 This question already has answers here : Is there a built-in login template in Django? (5 answers) Closed 3 years ago . I found some under the tests directory but I'm not sure if they are the right ones. By authentication templates I mean login.htm , password_reset.htm , etc. Some of the templates can be found at: http://devdoodles.wordpress.com/2009/02/16/user-authentication-with-django-registration/ 回答1: No, it looks for those templates in a "registration" directory within your templates

Django Postgres ArrayField aggregation and filtering

Deadly 提交于 2019-12-13 07:13:30
问题 Following on from this question: Django Postgresql ArrayField aggregation I have an ArrayField of Categories and I would like to retrieve all unique values it has - however the results should be filtered so that only values starting with the supplied string are returned. What's the "most Django" way of doing this? Given an Animal model that looks like this: class Animal(models.Model): # ... categories = ArrayField( models.CharField(max_length=255, blank=True), default=list, ) # ... Then, as

Editing a Django Comment

99封情书 提交于 2019-12-11 20:16:05
问题 I'm attempting to edit an existing comment (i.e. replace old comment with a new one). My comments app is django.contrib.comments. new_comment = form.cleaned_data['comment'] #all of the comments for this particular review comments = Comment.objects.for_model(Review).filter(object_pk=review_id) print comments[0].comment #'old comment' comments[0].comment = new_comment print comments[0].comment #'old comment' is still printed Why is the comment not being updated with the new comment ? Thank you.

Django - Read the current's user authentication backend class

穿精又带淫゛_ 提交于 2019-12-10 17:15:59
问题 I am using a custom authentication backend with Django, to automatically create and login users from a legacy system. My Backend class is this: from django.contrib.auth.backends import ModelBackend from django.contrib.auth.models import User from sfi.models import Employee import base64, hashlib class SFIUserBackend(ModelBackend): def authenticate(self, username=None, password=None): if not username or not password: return digest = base64.standard_b64encode(hashlib.md5(password).digest())

django: failing tests from django.contrib.auth

China☆狼群 提交于 2019-12-07 08:00:26
问题 When I run my django test I get following errors, that are outside of my test suite: ====================================================================== ERROR: test_known_user (django.contrib.auth.tests.remote_user.RemoteUserCustomTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 160, in test_known_user super(RemoteUserCustomTest, self).test_known

工具导航Map