django-views

Django automatic login after user registration (1.4)

霸气de小男生 提交于 2019-12-21 05:00:54
问题 I have an issue where I am successfully registering users - however, I want users to be logged in on registration. Here is the code that represents my registration view. Any thoughts on why the user is not auto-logged in? Notes: The user is being registered correctly, they can log in after this authenticate(**kwargs) is returning the correct user In settings.py I have: AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',) Thanks! def register(request): user_creation_form =

How to get a model object using model name string in Django

别等时光非礼了梦想. 提交于 2019-12-21 03:53:32
问题 Desciption: I have a generic function def gen(model_name,model_type): objects = model_name.objects.all() for object in objects: object.model_type = Null (Or some activity) object.save() How Can I achieve the above ? Is it possible? 回答1: I would use get_model : from django.db.models import get_model mymodel = get_model('some_app', 'SomeModel') 回答2: As of Django 1.7 the django.db.models.loading is deprecated (to be removed in 1.9) in favor of the the new application loading system. The 1.7 docs

How to get a model object using model name string in Django

房东的猫 提交于 2019-12-21 03:53:07
问题 Desciption: I have a generic function def gen(model_name,model_type): objects = model_name.objects.all() for object in objects: object.model_type = Null (Or some activity) object.save() How Can I achieve the above ? Is it possible? 回答1: I would use get_model : from django.db.models import get_model mymodel = get_model('some_app', 'SomeModel') 回答2: As of Django 1.7 the django.db.models.loading is deprecated (to be removed in 1.9) in favor of the the new application loading system. The 1.7 docs

Trying to trace a circular import error in Django

隐身守侯 提交于 2019-12-20 19:36:57
问题 I understand circular import error has been asked about a lot but after going through these questions I haven't been able to solve my issue. When I try to run my server in Django its giving me this error message: The included URLconf module 'accounts_app' from path\to\myproject\__init__.py does not appear to have any patterns in it. if you see valid patterns in the file then the issue is probably caused by a circular import. The issue started when i added a new app which has a urls.py like

Django pagination and “current page”

二次信任 提交于 2019-12-20 18:29:31
问题 I'm currently developing a Django application which will make use of the infamous "pagination" technique. I'm trying to figure out how the django.core.paginator module works. I have an application with a Question model. I will be listing all of the questions using this paginator. There will be 20 questions per page. def show_question(question_pk): questions = Question.objects.all() paginator = Paginator(questions, 20) page = ... # Somehow figure out which page the question is on return render

Trying to use django and dropzone/

跟風遠走 提交于 2019-12-20 14:45:49
问题 I'm trying to use dropzone.js with django. I'm following the somewhat dated guide here (https://amatellanes.wordpress.com/2013/11/05/dropzonejs-django-how-to-build-a-file-upload-form/) I strongly suspect My view is at issue. def test(request): print "test view has been called" if request.method == 'POST': print "test request method is POST" form = UploadFileForm(request.POST, request.FILES) print request print request.FILES if form.is_valid(): new_file = AttachedFiles(attachedfile=request

How to do a DetailView in django 1.3?

一个人想着一个人 提交于 2019-12-20 10:55:51
问题 I'm currently learning how to use the class-based views in django 1.3. I'm trying to update an application to use them, but I still don't uderstand very well how they work (and I read the entire class-based views reference like two or three times EVERY day). To the question, I have an space index page that needs some extra context data, the url parameter is a name (no pk, and that can't be changed, it's the expected behaviour) and the users that don't have that space selected in their

Django test RequestFactory vs Client

穿精又带淫゛_ 提交于 2019-12-20 09:56:14
问题 I am trying to decide whether I should use Django's Client or RequestFactory to test my views. I am creating my server using DjangoRESTFramework and it's really simple, so far: class SimpleModelList(generics.ListCreateAPIView): """ Retrieve list of all route_areas or create a new one. """ queryset = SimpleModel.objects.all() serializer_class = SimpleModelSerializer filter_backends = (IsOwnerFilterBackend,) def perform_create(self, serializer): serializer.save(owner=self.request.user) What are

AssertionError: `HyperlinkedIdentityField` requires the request in the serializer context

瘦欲@ 提交于 2019-12-20 08:57:28
问题 I want to create a many-to-many relationship where one person can be in many clubs and one club can have many persons. I added the models.py and serializers.py for the following logic but when I try to serialize it in the command prompt, I get the following error - What am I doing wrong here? I don't even have a HyperlinkedIdentityField Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Users\user\corr\lib\site-packages\rest_framework\serializers.py", line 503,

How to fix-no such table: main.auth_user__old

十年热恋 提交于 2019-12-20 07:38:21
问题 Can someone give a detailed explanation on how to fix the ERROR: no such table: main.auth_user__old It arises in my Django application when I am trying to add data to my registered models. 回答1: It's a compatibility issue between latest SQLite and Django. See here: Django - No such table: main.auth_user__old 回答2: I have solved this issue using below : 1) Delete the db.sqlit3 2) app's directory delete everything in pycache 3) manage.py makemigrations, manage.py migrate, manage.py