These are chat archives for django/django

13th
Dec 2017
Amritpal Singh
@amrit3701
Dec 13 2017 05:48
Hi
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:
static
├── admin
└── rest_framework
Amritpal Singh
@amrit3701
Dec 13 2017 05:55
Can anybody help me for figuring out this issue?
Amritpal Singh
@amrit3701
Dec 13 2017 07:21
@bittner Yes, I have ran this already. Actually I used django server python manage.py 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
@denizs
Dec 13 2017 09:42
@MariosPanag simply add your authentication class to the tuple like so:
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'absolute.path.to.my.AuthClass',   
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
    ),
}
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
@kaushal087
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?
Django==1.9.1
djangorestframework==3.6.3
Amritpal Singh
@amrit3701
Dec 13 2017 11:32

Hello,
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
@amrit3701
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                                                 
        else:                                                           
            return request.method in permissions.SAFE_METHODS
Peter Bittner
@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
@amrit3701
Dec 13 2017 13:43
@bittner Okay, I agreed. I will deploy my Django app using Nginx on production.
matrixbot
@matrixbot
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
vanguar
@vanguar
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 pythonanywhere.com 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.
Luke-VideoLibre
@LukeVideo
Dec 13 2017 14:59
did you try a git clone?
Are you in a special branch?
vanguar
@vanguar
Dec 13 2017 15:34
No, I did not. I'm in a single master branch
vanguar
@vanguar
Dec 13 2017 15:51
I'm sorry. Yes, I used the command: git clone
emihir0
@emihir0
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