我正在寫一個Django應用程序,我在網上部署它,但我遇到了一些靜態文件的問題。當我運行collectstatic命令時,它說'沒有名稱模塊'。我看過這裏的問題,沒有人回答我的問題。Django靜態文件沒有模塊名爲<app_name>
我的靜態文件被愚蠢地放到應用程序特定的目錄中,但是我將它們移出並嘗試在正確的目錄中運行它,但仍然沒有運氣。
這真的很奇怪:
Settings.py:
"""
Django settings for django_project project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'secret'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_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',
'ticketr', # App name
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'django_project.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 = 'django_project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, '../db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATICFILES_DIRS = '/home/django/ticketr/static'
# Tried it at: '/home/django/django_project/django_project/static'
# Also tried it at: '/home/django/static'
STATIC_URL = '/static/'
目錄
.
├── db.sqlite3
├── django_project
│ ├── db.sqlite3
│ ├── django_project
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── settings.py
│ │ ├── settings.pyc
│ │ ├── settings.pye
│ │ ├── urls.py
│ │ ├── urls.pyc
│ │ ├── wsgi.py
│ │ └── wsgi.pyc
│ └── manage.py
├── images
│ ├── event_images
├── media
│ ├── images
│ └── qrcode
├── qrcode
├── templates
└── ticketr
├── admin.py
├── admin.pyc
├── apps.py
├── forms.py
├── forms.pyc
├── helper.py
├── helper.pyc
├── __init__.py
├── __init__.pyc
├── media
│ └── images
│ └── event_images
├── migrations
├── models.py
├── models.pyc
├── static
│ ├── css
│ │ ├── bootstrap.css
│ │ ├── bootstrap.css.map
│ │ ├── bootstrap.min.css
│ │ ├── bootstrap.min.css.map
│ │ ├── bootstrap-theme.css
│ │ ├── bootstrap-theme.css.map
│ │ ├── bootstrap-theme.min.css
│ │ └── bootstrap-theme.min.css.map
│ ├── fonts
│ │ ├── glyphicons-halflings-regular.eot
│ │ ├── glyphicons-halflings-regular.svg
│ │ ├── glyphicons-halflings-regular.ttf
│ │ ├── glyphicons-halflings-regular.woff
│ │ └── glyphicons-halflings-regular.woff2
│ ├── images
│ │ ├── background1.png
│ │ ├── event_images
│ │ ├── logo.png
│ │ └── qr.jpg
│ └── js
│ └── bootstrap.min.js
├── templatetags
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── ticket_extras.py
│ └── ticket_extras.pyc
├── tests.py
├── urls.py
├── urls.pyc
├── views.py
└── views.pyc
不行不行。我添加了靜態文件查找器,我不認爲我需要它們,因爲django.contrib.staticfiles已包含在內。但我將靜態根目錄更改爲它在我的應用程序中的目錄,但它仍然無效。 –
@MarkBarrett STATIC_ROOT應該是一個新的目錄,就像'./ static /'在那裏收集文件......而不是從哪裏收集靜態文件。 Collectstatic會在您指定的所有目錄中找到靜態文件,並將它們收集在一個地方。 – YPCrumble
@MarkBarrett我猜這個問題是我的編輯,你的目錄結構。 – YPCrumble