These are chat archives for django/django

29th
Jun 2017
Ghost
@ghost~58f4b458d73408ce4f58f2fa
Jun 29 2017 04:33 UTC
hello everyone.can anyone please advise me on how to serve django static files in production with nginx? ive followed every step in the docs(including collectstatic and changing directory path to www-data ) but i still get a 403 error on all css and images..please help.
Anish Shrestha
@annshress
Jun 29 2017 04:56 UTC
how can i serve staticfiles with DEBUG = FALSE
@annshress
Anish Shrestha
@annshress
Jun 29 2017 05:19 UTC
without doing collectstatic
John
@flyboy1565
Jun 29 2017 05:21 UTC
Serving static files from a dedicated server?
Shashank Parekh
@sp1rs
Jun 29 2017 06:07 UTC
We are using tastypie /django, and as we moved from django 1.8 to 1.11
Our tastypie apis is throwing 401 error. Any idea? Currently we are using 2 server, 1 server serving django1.8 and other 1.11.
John
@flyboy1565
Jun 29 2017 06:12 UTC
what error messages are you receiving?
Shashank Parekh
@sp1rs
Jun 29 2017 06:12 UTC
401 unauthorized
For most of the POST request.
I am guessing that it could be because of CSRF token?
John
@flyboy1565
Jun 29 2017 06:18 UTC
espically if they are both using the same database
3wade3
@3wade3
Jun 29 2017 06:24 UTC
Hello. I am using drf and rest-auth. I send token from frontend in request header (Authorization:Token 7d2ee4481ea0e12bd88f46d57e2e6dab3354d4b0). But this request seems like unauthorized. When i get user like this (request.user) it returns Anonymous user
Shashank Parekh
@sp1rs
Jun 29 2017 06:41 UTC
@flyboy1565 Yes same database
Shashank Parekh
@sp1rs
Jun 29 2017 06:57 UTC

Could that be the issue?

Changed in Django 1.10:
Added salting to the token and started changing it with each request to protect against BREACH attacks.

John
@flyboy1565
Jun 29 2017 06:59 UTC
I would make the Django 1.11 version its own accounts database, and migrate the profiles
users may need to create a new auth token by logging in
Shashank Parekh
@sp1rs
Jun 29 2017 07:06 UTC
@flyboy1565 Can’t we disable this
So that it is backward compatibile?
John
@flyboy1565
Jun 29 2017 07:08 UTC
I'm not certain.. sorry
Shashank Parekh
@sp1rs
Jun 29 2017 07:08 UTC
Such a pain migrating to new version…:(
John
@flyboy1565
Jun 29 2017 07:09 UTC
yup, lots of testing before doing a production swap
usually I migrate everything except the users session.. run a function to add all but the tokens/session ids.. this way they are prompted to login again
jabalv
@jabalv
Jun 29 2017 07:10 UTC
I have django project and I want to develope API. I found that there is already API framework for Django: http://www.django-rest-framework.org/
Do you have any comments about it? Maybe something else?
Shashank Parekh
@sp1rs
Jun 29 2017 07:11 UTC
drf is goog or you can also use tastypie.
but i think tastypie is outdated
good*
John
@flyboy1565
Jun 29 2017 07:12 UTC
drf is great... i'm working to turn my entire project to use drf for backend and vue2 or angular for frontend
John
@flyboy1565
Jun 29 2017 07:12 UTC
nice thing about it is you can also setup a curl commandd
jabalv
@jabalv
Jun 29 2017 07:14 UTC
@flyboy1565 Seems not outaded from github
Shashank Parekh
@sp1rs
Jun 29 2017 07:15 UTC
@jabalv use drf
better than tastypie
John
@flyboy1565
Jun 29 2017 07:18 UTC
i didn't say anything about tastypie... also you can use flask...
Adam Hopkins
@ahopkins
Jun 29 2017 07:23 UTC
+1 for DRF ... (1) easy easy to get up and running, (2) extremely powerful to manipulate if you need more control
John
@flyboy1565
Jun 29 2017 07:33 UTC

so here is a quick DRF question

I am trying to use a Channels with Django Rest Framework

#signals.py
@receiver(post_save, sender=CommunicationsIssue)
def communications_issue_post_save(sender, **kwargs):
    send_notification({
        'type': 'post_save',
        'issue': kwargs['instance'].__dict__
    })

I want to convert the kwargs['instance'].__dict__ to json. I have an existing serializer that handles CommunicationIssueDetails. but how do i use it?

Shashank Parekh
@sp1rs
Jun 29 2017 07:42 UTC
Is tastypie latest version supporting django 1.11?
Adam Hopkins
@ahopkins
Jun 29 2017 07:44 UTC
@flyboy1565 Have you seen this: https://github.com/linuxlewis/channels-api
and, first, I think you mean for that to be kwargs['instance'].__dict__()
but, if you specifically need to pass it as JSON: json.dumps()
Ghost
@ghost~58f4b458d73408ce4f58f2fa
Jun 29 2017 08:01 UTC
@flyboy1565 serving static files from a vps
@annshress without doing collectstatic? but the django documentation states that you should collect static in production..or what exactly did you mean?
Anish Shrestha
@annshress
Jun 29 2017 08:07 UTC
Its ok. Had a confusion @gathagu354 @flyboy1565
Pavel Burns
@63phc
Jun 29 2017 09:03 UTC
Hello Give me something to read how to deploy in a docker project with Django plz
@63phc those helped me
and this one too
brianbola
@brianbola
Jun 29 2017 15:08 UTC
Im stuck on a headbanging issue.
Im trying to take a list of skills in a user profile form but have no idea how to take a comma seperated list of skills and store in model(DB) anyone implement such a thing before ?
any help links appreciated
Shashank Parekh
@sp1rs
Jun 29 2017 15:16 UTC
@brianbola Convert the list into string and store it.
brianbola
@brianbola
Jun 29 2017 15:18 UTC
they are stored as one string
What im trying to do is like what linkedin has. you have one form field where you can add multiple skills but cant figure out how they done it.
@sp1rs tbanks for responding :)
:)
Shashank Parekh
@sp1rs
Jun 29 2017 15:25 UTC
hehe okay
John
@flyboy1565
Jun 29 2017 18:40 UTC
@ahopkins , yes I have and was hoping to start using it.. but wanted to get my head around just using standard channels. I was going to build a simple page where I could push changes using the post_save signal
Felipe Campelo
@fccampelo
Jun 29 2017 20:37 UTC
I'm doing a deploy inside heroku and it throws the following error:
 Installing requirements with pip
       Collecting dj-database-url==0.4.1 (from -r /tmp/build_6e2012c16c4f23ee083443c8a0db85f8/requirements.txt (line 1))
         Downloading dj-database-url-0.4.1.tar.gz
       Collecting Django==1.9.5 (from -r /tmp/build_6e2012c16c4f23ee083443c8a0db85f8/requirements.txt (line 2))
         Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB)
       Collecting gunicorn==19.4.5 (from -r /tmp/build_6e2012c16c4f23ee083443c8a0db85f8/requirements.txt (line 3))
         Downloading gunicorn-19.4.5-py2.py3-none-any.whl (112kB)
       Collecting psycopg2==2.7.1 (from -r /tmp/build_6e2012c16c4f23ee083443c8a0db85f8/requirements.txt (line 4))
         Downloading psycopg2-2.7.1-cp35-cp35m-manylinux1_x86_64.whl (2.7MB)
       Installing collected packages: dj-database-url, Django, gunicorn, psycopg2
         Running setup.py install for dj-database-url: started
           Running setup.py install for dj-database-url: finished with status 'done'
       Successfully installed Django-1.9.5 dj-database-url-0.4.1 gunicorn-19.4.5 psycopg2-2.7.1
-----> $ python manage.py collectstatic --noinput
       Traceback (most recent call last):
         File "manage.py", line 10, in <module>
           execute_from_command_line(sys.argv)
         File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
           utility.execute()
         File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
           self.fetch_command(subcommand).run_from_argv(self.argv)
         File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 195, in fetch_command
           klass = load_command_class(app_name, subcommand)
         File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 40, in load_command_class
           return module.Command()
         File "/app/.heroku/python/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 32, in __init__
           self.storage.path('')
         File "/app/.heroku/python/lib/python3.5/site-packages/django/contrib/staticfiles/storage.py", line 48, in path
           raise ImproperlyConfigured("You're using the staticfiles app "
       django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
 !     Error while running '$ python manage.py collectstatic --noinput'.
       See traceback above for details.
       You may need to update application code to resolve this error.
       Or, you can disable collectstatic for this application:
          $ heroku config:set DISABLE_COLLECTSTATIC=1
       https://devcenter.heroku.com/articles/django-assets
 !     Push rejected, failed to compile Python app.
 !     Push failed
Does anyone know how I can solve this problem?
John
@flyboy1565
Jun 29 2017 20:44 UTC
@fccampelo do you have your static root set? You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path
Felipe Campelo
@fccampelo
Jun 29 2017 20:45 UTC
"""
Django settings for djangoecommerce project.

Generated by 'django-admin startproject' using Django 1.9.5.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os
import dj_database_url


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '(0a0@*)n*@c^q%1ha8ipz$rf9t21z(0l4w2+x1&g&29z3c)tk+'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'core',
]

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'djangoecommerce.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'djangoecommerce.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'pt-br'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'

db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

ALLOWED_HOSTS = ['*']

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')

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

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
this is my code
@flyboy1565
John
@flyboy1565
Jun 29 2017 20:47 UTC
this was pushed to your heroku instance
Felipe Campelo
@fccampelo
Jun 29 2017 20:47 UTC
yes
The error appears in my heroko
Felipe Campelo
@fccampelo
Jun 29 2017 20:52 UTC
heroku*
John
@flyboy1565
Jun 29 2017 20:53 UTC
sorry then.. outta ideas
frederickv
@fredypaulov_twitter
Jun 29 2017 23:22 UTC
hi
hi every body
i am new to python i wan to know
how to remember like 300 or 400 lines of code in python
in 20 minutes
it is for an exam
can anyone can hel me?
help me please?
John
@flyboy1565
Jun 29 2017 23:23 UTC
how to remember/
frederickv
@fredypaulov_twitter
Jun 29 2017 23:24 UTC
yeah to remember it is for an exam
thers a lot of functions and modules to remember it for the exam
????
help me please
...
John
@flyboy1565
Jun 29 2017 23:26 UTC
I don't know how we would help you remember them.. maybe explain what the code does sure, but the powers of retention are up to you
frederickv
@fredypaulov_twitter
Jun 29 2017 23:27 UTC
uy and now???
may be i should type a loyt in the computer and
and how it works do you think this can me a lot
in the long run ???
???
and know how itr work can this help me ??
the code is about bank transaction
the client/ usder ask for menet to the atm machine and the atm amchine
get the money in
this msut e one bye th code
it as alpong code
John
@flyboy1565
Jun 29 2017 23:31 UTC
so you need to write some code to prepare for an exam?
frederickv
@fredypaulov_twitter
Jun 29 2017 23:31 UTC
yeah sort of
yes
i want to k now if i can show it to you and tyou can improve it
or helpo me on that??
???
John
@flyboy1565
Jun 29 2017 23:32 UTC
I'm ok with helping you improve what you have when you have free time
you can pm me..
frederickv
@fredypaulov_twitter
Jun 29 2017 23:33 UTC
ok so what do you need know to make it happen??
pm me??
how??
chat privztely ok but but how can i do that???
frederickv
@fredypaulov_twitter
Jun 29 2017 23:48 UTC
@fredypaulov_twitter
ok
so the best way that i used to remeber code that is the way that i mustr used to remember my code ok
so i can give you to cide now so you can chek it upo please??
??
please help me please???