N
N
Nikolai Vinogradov2017-02-02 19:26:39
Django
Nikolai Vinogradov, 2017-02-02 19:26:39

When starting a django application with apache2, the view stops working, giving 500. How to fix it?

I use DRF with TokenAuthentication, when the raw application is running, everything works good, everything saves, everything connects. Scheme of work:

  1. User registers
  2. User submits a list of objects to save
  3. The view saves objects, linking each of them to the user who sent them along the way
  4. Other actions

The problem is in the place. where I am trying to bind the user and the newly created object. The code looks something like this:
serializer.save() # сохраня. объект
profile = Profile.objects.get(id=request.user.id)#беру текущего юзера
created = Rater.objects.latest('name')# беру последний созданный объект Rater
profile.raters.add(created) #добавля. пользователю
profile.save() сохраняю пользователя(апдейт)

And then it gives me
500 DoesNotExist at /v1/raters/↵Profile matching query does not exist.

Question: why does it work on a raw application (I run it in a vagrant, I myself sit from Windows), but when I configure Apache with mod_wsgi in the same vagrant, everything goes to hell?
UPD: Profile - custom model for AUTH_USER_MODEL.
UPD 2: Apparently, Apache does not allow you to see the user from request.user, because it swears at
profile = Profile.objects.get(id=request.user.id)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Vinogradov, 2017-02-02
@Kibastus

I will duplicate the answer here:
It was necessary to add WSGIPassAuthorization On to the Apache config, without which Apache cuts off the header with authorization.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question