2017-04-19 57 views
1

我正在寫一個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 

回答

0

所以基本上我的問題是一些事情。我安裝了一個新的液滴,然後重新開始工作:

  1. 我的應用程序位於錯誤的目錄中。它必須位於manage.py文件所在目錄中的django_project目錄中。
  2. 如前所述上面,我不得不改變我的STATIC_URL和STATIC_ROOT
  3. 一旦多數民衆贊成做我不得不重新啓動gunicorn並使用刷新靜態文件:

    蟒蛇manage.py collectstatic --noinput --clear

    NB。確保應用程序與django_project位於同一目錄中。 home/django/django_project < - 在那裏。

0

確保您設置STATICFILES_FINDERSdefault setting in the docs - 這就是發現靜態文件在你的應用中。您的靜態文件適當位於應用程序中的/static/文件夾中,因此您可以刪除STATICFILES_DIRS設置。

您可能還想添加一個STATIC_ROOTSTATIC_URLthe docs以及。

編輯:你也有一個奇怪的目錄結構。它應該看起來更像https://stackoverflow.com/a/41963237/2532070 - ticketr目錄在第一個django_project目錄內,與manage.py位於同一級別。

+0

不行不行。我添加了靜態文件查找器,我不認爲我需要它們,因爲django.contrib.staticfiles已包含在內。但我將靜態根目錄更改爲它在我的應用程序中的目錄,但它仍然無效。 –

+0

@MarkBarrett STATIC_ROOT應該是一個新的目錄,就像'./ static /'在那裏收集文件......而不是從哪裏收集靜態文件。 Collectstatic會在您指定的所有目錄中找到靜態文件,並將它們收集在一個地方。 – YPCrumble

+0

@MarkBarrett我猜這個問題是我的編輯,你的目錄結構。 – YPCrumble

相關問題