These are chat archives for django/django

Dec 2017
Amritpal Singh
Dec 13 2017 05:48
I unable to load static files when DEBUG is False.
STATIC_URL = '/static/'                                                 

STATICFILES_DIRS = (                                                    
    os.path.join(BASE_DIR, 'static'),                                   

STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles"
here is tree structure of my <project>/static folder:
├── admin
└── rest_framework
Amritpal Singh
Dec 13 2017 05:55
Can anybody help me for figuring out this issue?
Amritpal Singh
Dec 13 2017 07:21
@bittner Yes, I have ran this already. Actually I used django server python runserver with DEBUG is False.
@bittner on searching from internet, I found that --insecure flag force serving of static files with the staticfiles app even if the DEBUG setting is False which solves my purpose.
Deniz Saner
Dec 13 2017 09:42
@MariosPanag simply add your authentication class to the tuple like so:
rest_framework will go ahead and look at this tuple, trying to authenticate a user with one of the authentication classes.
Quick question on my own - has anyone integrated a multi step form wizard into the django admin panel?
Kaushal Kumar
Dec 13 2017 10:48
I am using custom permission in my View.
class UserDetailsCreate(APIView):

    permission_classes = (IsUserVerified, )

    def put(self, request, user_id, *args, **kwargs):
It return 403 response code. I wan't to return custom error code like 444 and custom error message.
How can I do that?
Amritpal Singh
Dec 13 2017 11:32

I am using Django rest framework and stuck at below point:

How to set permission like only if user is anonymous then only he will send post request?
I have set permission like permission_classes = (permissions.AllowAny,)
but with this authenticated user also send post request.

@mariocesar @sayanchowdhury ?
Amritpal Singh
Dec 13 2017 12:00
Yeah! I have created my custom permission class which solves my purpose:
class AllowOnlyAnonymous(permissions.BasePermission):                   
    Allow only anonymous user to POST.                                  

    def has_permission(self, request, view):                            
        if request.user.is_anonymous:                                   
            return True                                                 
            return request.method in permissions.SAFE_METHODS
Peter Bittner
Dec 13 2017 13:03
@amrit3701 No, don't ever ever ever use a flag that is named "insecure"! It is called insecure for a reason. This flag is not meant for production use, it's - if at all - meant for trouble shooting, no more. -- Read the docs thoroughly. Try to understand how staticfiles works. You also need to use the static template tag in your templates. It's not too difficult to get it right. Don't do shit. It's dangerous.
Amritpal Singh
Dec 13 2017 13:43
@bittner Okay, I agreed. I will deploy my Django app using Nginx on production.
Dec 13 2017 13:55

Synekal What's the best way to go about deploying large ML models in a Django server?

Unpickle the models each time a request comes in? Is this too slow?

Caching? Memcached is 128MB max per item which is too low for me

Are there other options?

Synekal The intention is that you can get predctions synchronously by hitting a url with some parameters
Dec 13 2017 14:51
Good day to everyone. Sorry for the stupid question, but I ran into a problem. When typing a command in the console: git pull, the process of downloading files from the repository to Github takes place. But in the end, the files are not updated. Thank you in advance for your cooperation.
Dec 13 2017 14:59
did you try a git clone?
Are you in a special branch?
Dec 13 2017 15:34
No, I did not. I'm in a single master branch
Dec 13 2017 15:51
I'm sorry. Yes, I used the command: git clone
Dec 13 2017 19:16
Is there an inbuilt 'year-month' and/or 'year' field? It's such a common need that I'm surprised that google results only bring up some hackish solutions to it
of course the date would be still stored as datefield on db level, but it's pointless to show day/month in a lot of cases (credit card expiration for example)
it's not a good way to store year as integer field (and/or year, month as 2 fields) simply because the great builtin functionality of being able filter and treat it as a date object would be lost