Python social auth, Facebook, Twitter, and Google Auth with static files
We have two new directories under ~/public_html/djsite:
bogotob1@bogotobogo.com [~/public_html/djsite]# ls ./ ../ djauth.fcgi* .htaccess media/ static/
Websites generally need to serve additional files such as images, JavaScript, or CSS which are referred as static files. Django provides django.contrib.staticfiles to help us manage them. This section describes how we can serve these static files in production.
We should make sure that django.contrib.staticfiles is included in our INSTALLED_APPS in djauth/settings.py:
# Application definition INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'djauthapp', 'social.apps.django_app.default', )
When we deploy the static files, django.contrib.staticfiles provides a convenience management command for gathering static files in a single directory so we can serve them easily.
In our settings file, as shown earlier, we defined STATIC_URL, for example:
STATIC_URL = '/djsite/static/'
Set the STATIC_ROOT to the directory from which we like to serve these files. So, when we do collectstatic, it will copy all files from our static folders into the STATIC_ROOT directory. In my case, it is:
STATIC_ROOT = "/home2/bogotob1/www/djsite/static/"
Let's run the collectstatic management command:
bogotob1@bogotobogo.com [~/DjangoAuthProject/djauth]# python manage.py collectstatic /home2/bogotob1/python/lib/python2.7/site-packages/social/apps/django_app/default/models.py:29: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.UserSocialAuth doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9. class UserSocialAuth(models.Model, DjangoUserMixin): ... 62 static files copied to '/home2/bogotob1/www/djsite/static'. bogotob1@bogotobogo.com [~/DjangoAuthProject/djauth]#
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization