0

I am currently using django version 1.9. I try to create a new superuser then I run the server and try to login through the browser by navigating to 127.0.0.1:8000/admin, but the django admin page seem does not have any css. When i do inspect element in the browser itself I come to know that it link to two css files one is base.css and another one is login.css but those two contain nothing when i try to view it from the browser. After that i try to find those file in the installed django directory and i found out the base.css and login.css then i copy the all the code in that file to the base.css and login.css which i opened in the browser, then i got the beautiful django login page with proper css. I don't know what to do with this.

This is my console:

Here is the screenshot

I am using python 3.4.3 and django1.9.0. Thanks

Ken Phanith
  • 53
  • 1
  • 6

2 Answers2

1

You have to set STATIC_ROOT, STATIC_URL and STATICFILES_DIRS in settings.py as below:

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

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

and then try to run:

python manage.py collectstatic
Aida.Mirabadi
  • 996
  • 4
  • 10
  • 27
0

If you are using django-rest-framework see this.

You need to add it as,

INSTALLED_APPS = (
    ...
    'rest_framework',
)

and in urls.py:

urlpatterns = [
    ...
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]

It will automatically search and catch all the static files.

Piyush S. Wanare
  • 4,703
  • 6
  • 37
  • 54