django

django admin - You don't have permission to edit anything

大城市里の小女人 提交于 2021-02-19 00:53:21
问题 I followed the django doc on creating a custom user model while extending the model itself with my own fields. So it became like this: class MyUser(AbstractBaseUser, PermissionsMixin): email = models.EmailField(max_length=255, unique=True) first_name = models.CharField(max_length=35) last_name = models.CharField(max_length=35) username = models.CharField(max_length=70, unique=True) date_of_birth = models.DateField() is_active = models.BooleanField(default=True) is_admin = models.BooleanField

django admin - You don't have permission to edit anything

拥有回忆 提交于 2021-02-19 00:46:18
问题 I followed the django doc on creating a custom user model while extending the model itself with my own fields. So it became like this: class MyUser(AbstractBaseUser, PermissionsMixin): email = models.EmailField(max_length=255, unique=True) first_name = models.CharField(max_length=35) last_name = models.CharField(max_length=35) username = models.CharField(max_length=70, unique=True) date_of_birth = models.DateField() is_active = models.BooleanField(default=True) is_admin = models.BooleanField

Nginx (I think) saves files with wrong permissions when request is too large

£可爱£侵袭症+ 提交于 2021-02-18 23:00:26
问题 So, I'm completely new to hosting and Linux and all, so please forgive me if I'm saying things that are wrong. I'm still learning :) I'm working a small personal website created using Django. I wanted to get it online to see if everything would work. I got a cheap server from linode and using a guide from Digital-Ocean (the irony) I got everything working. I was happy. But... There's one major problem and I've read half the internet and can't find any similar problems: when the post request

Token in query string with Django REST Framework's TokenAuthentication

醉酒当歌 提交于 2021-02-18 22:55:41
问题 In an API built with Django REST Framework authentication can be done using the TokenAuthentication method. Its documentation says the authentication token should be sent via an Authorization header. Often one can send API-keys or tokens via a query string in order to authenticate, like https://domain.com/v1/resource?api-key=lala . Is there a way to do the same with Django REST Framework's TokenAuthentication? 回答1: By deafult DRF doesn't support query string to authenticate, but you can

Token in query string with Django REST Framework's TokenAuthentication

Deadly 提交于 2021-02-18 22:55:07
问题 In an API built with Django REST Framework authentication can be done using the TokenAuthentication method. Its documentation says the authentication token should be sent via an Authorization header. Often one can send API-keys or tokens via a query string in order to authenticate, like https://domain.com/v1/resource?api-key=lala . Is there a way to do the same with Django REST Framework's TokenAuthentication? 回答1: By deafult DRF doesn't support query string to authenticate, but you can

Where can I access request parameters in Django Rest Framework?

大兔子大兔子 提交于 2021-02-18 22:37:07
问题 I'm using Django Rest Framework and python-requests and passing several variables through the URL as shown below. "GET /api/boxobjects/?format=json&make=Prusa&model=i3&plastic=PLA HTTP/1.1" So I'm passing the variables make, model, and plastic. The recommended method to access these parameters is shown below. makedata = request.GET.get('make', '') However, I have no idea where to place that line of code. I've completed the tutorial for Django Rest Framework and have my views set up to roughly

Django: query spanning multiple many-to-many relationships

最后都变了- 提交于 2021-02-18 22:36:50
问题 I've got some models set up like this: class AppGroup(models.Model): users = models.ManyToManyField(User) class Notification(models.Model): groups_to_notify = models.ManyToManyField(AppGroup) The User objects come from django's authentication system. Now, I am trying to get all the notifications pertaining to the groups that the current user is a part of. I have tried.. notifications = Notification.objects.filter(groups_to_notify=AppGroup.objects.filter(users=request.user)) But that gives an

Where can I access request parameters in Django Rest Framework?

*爱你&永不变心* 提交于 2021-02-18 22:36:46
问题 I'm using Django Rest Framework and python-requests and passing several variables through the URL as shown below. "GET /api/boxobjects/?format=json&make=Prusa&model=i3&plastic=PLA HTTP/1.1" So I'm passing the variables make, model, and plastic. The recommended method to access these parameters is shown below. makedata = request.GET.get('make', '') However, I have no idea where to place that line of code. I've completed the tutorial for Django Rest Framework and have my views set up to roughly

Random string in template django

為{幸葍}努か 提交于 2021-02-18 22:28:36
问题 Is there any way to have a random string in a django template ? I would like to have multiple strings displaying randomly like: {% here generate random number rnd ?%} {% if rnd == 1 %} {% trans "hello my name is john" %} {% endif %} {% if rnd == 2 %} {% trans "hello my name is bill" %} {% endif %} EDIT: Thanks for answer but my case needed something more specific as it was in the base template (wich I forgot to mention sorry ) . So after crawling google and some doc I fall on context

How to apply a decorator to all views (of a module) in django

点点圈 提交于 2021-02-18 22:21:13
问题 It happens a lot, when all the views in a specific module are supposed to be available only when the user is authorized, or they should all do the same checks. How could I avoid repeating the annotations all over the file? 回答1: When using class-based views you can create a base class/mixin for all these views which implements the desired functionality (also using decorators) and then have all the views inherit from this base view. from django.views.generic import TemplateView class BaseView