Skip to main content

Mengatur static folder

static folder digunakkan untuk menyimpan file file static.

ketika menjalankan command berikut

python manage.py collectstatic

maka semua file static seperti css,javascript akan dikumpulkan didalalm folder static tersebut.

untuk mengatur folder static, buka terlebih dahulu file myproject/settings.py, dan tambahkan kode berikut

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

dan tambahkan routing folder staticnya di file myproject/urls.py seperti ini

from django.contrib import admin

# import static dan settings
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
path('admin/', admin.site.urls),
# other urls
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) # tambahkan kode berikut

kemudian jalankan perintah

python manage.py collectstatic