简体   繁体   English

用django在heroku上部署bootstrap

[英]deploying bootstrap on heroku with django

I am having trouble with deployment of twitter bootstrap on my heroku client. 我在heroku客户端上部署twitter bootstrap遇到麻烦。 My html code is not showing like it should (alignment, special table layouts, etc) 我的html代码未按应有的方式显示(对齐方式,特殊的表格布局等)

All is working locally, but i assume it has to do with the static files that don't get transferred correctly. 所有人都在本地工作,但我认为这与无法正确传输的静态文件有关。

This is the static file structure, but have a look how it looks like when i open the "source chrome console" on my live heroku verson. 这是静态文件结构,但请看一下在我的实时Heroku版本中打开“源chrome控制台”时的外观。

View of how the folder structure should be 文件夹结构应如何的视图

在此处输入图片说明

Folder structure of deployed code on heroku heroku上已部署代码的文件夹结构

在此处输入图片说明

It looks like some folders are "stitched" one to another. 看起来有些文件夹是彼此“缝合”的。 what could be my issue? 我的问题是什么? should i avoid "-" and "_" in my file names? 我应该在文件名中避免使用“-”和“ _”吗?

thanks for the help. 谢谢您的帮助。

based on extra questions, I added more info on my settings.py file. 基于其他问题,我在settings.py文件中添加了更多信息。 I followed a tutorial to get all the stuff right. 我遵循了一个教程来正确处理所有内容。 Also whitenoise was installed, added to wsgi.py. 还安装了whitenoise,将其添加到wsgi.py中。

wsgi.py wsgi.py

"""
WSGI config for xforward project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""

import os
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xforward.settings")

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()
application = DjangoWhiteNoise(application)

settings.py settings.py

-- -

"""
Django settings for xforward project on Heroku. For more info, see:
https://github.com/heroku/heroku-django-template

For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""

import os
import dj_database_url

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "{{ secret_key }}"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.admindocs', ### onbekend of deze nodig is
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # Disable Django's own staticfiles handling in favour of WhiteNoise, for
    # greater consistency between gunicorn and `./manage.py runserver`. See:
    # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'frontendapp',
]

LOGIN_REDIRECT_URL = 'forwardthis'

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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 = 'xforward.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
            'debug': DEBUG,
        },
    },
]

WSGI_APPLICATION = 'xforward.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('postgresname'),
        'USER': os.environ.get('postgresuser'),
        'PASSWORD': os.environ.get('postgrespassword'),
        'HOST': os.environ.get('postgreshost'),
        'PORT': os.environ.get('postgresport'),
    }
}

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# Update database configuration with $DATABASE_URL.
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['*']

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, 'static'),
]

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

-- -

After having a thorough discussion with hansTheFranz, it became clear that the issues had to do with missing files. 与hansTheFranz进行了深入讨论之后,很明显,问题与丢失的文件有关。

A default gitnore used in my sourcetree application that i used for syncing with github, prevented several static folders to upload to my git. 我用于与github同步的sourcetree应用程序中使用的默认gitnore阻止了几个静态文件夹上传到我的git。 removing these folders from this gitnore file did the trick. 从这个gitnore文件中删除这些文件夹就可以了。

thanks for the help guys! 谢谢你们的帮助!

Go to heroku static assets documentation for Django: 转到Django的heroku静态资产文档:

Heroku Documentation: Django and Static Assets Heroku文档:Django和静态资产

Everything is illustrated there in detail, make changes in settings.py and install whitenoise and it will work. 一切都在此处详细说明,在settings.py中进行更改并安装whitenoise ,它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM