0

我正在努力将 React 与 Django 1.10 结合起来,并且在尝试配置管道时遇到了非常时髦的活动。

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\django\core\management\__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\django\core\management\base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 193, in handle
    collected = self.collect()
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 139, in collect
    for original_path, processed_path, processed in processor:
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\pipeline\storage.py", line 26, in post_process
    packager.pack_stylesheets(package)
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\pipeline\packager.py", line 96, in pack_stylesheets
    variant=package.variant, **kwargs)
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\pipeline\packager.py", line 105, in pack
    paths = self.compile(package.paths, force=True)
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\pipeline\packager.py", line 34, in paths
    return [path for path in self.sources
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\pipeline\packager.py", line 27, in sources
    if path not in paths and find(path):
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\django\contrib\staticfiles\finders.py", line 250, in find
    result = finder.find(path, all=all)
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\django\contrib\staticfiles\finders.py", line 160, in find
    match = self.find_in_app(app, path)
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\django\contrib\staticfiles\finders.py", line 174, in find_in_app
    if storage.exists(path):
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\django\core\files\storage.py", line 394, in exists
    return os.path.exists(self.path(name))
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\django\core\files\storage.py", line 407, in path
    return safe_join(self.location, name)
  File "C:\Users\Matt\Envs\my-site\lib\site-packages\django\utils\_os.py", line 78, in safe_join
    'component ({})'.format(final_path, base_path))
django.core.exceptions.SuspiciousFileOperation: The joined path (C:\) is located outside of the base path component (C:\Users\Matt\Envs\my-site\lib\site-packages\django\contrib\admin\static)

我不明白这个异常是如何发生的,因为我对 Django 很陌生。

如果您需要更多信息来解决此问题,请告诉我。我怀疑这个问题是由于在设置中配置我的管道时疏忽造成的,但我现在真的不知道。谢谢!

附录:这是我尝试 django 项目并导航到其中一个应用程序的索引页面时的堆栈跟踪:

Request Method: GET
Request URL: http://127.0.0.1:8000/my-app/

Django Version: 1.10.5
Python Version: 3.5.1
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'pipeline',
 'rest_framework',
 'MyApp']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 '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']


Template error:
In template C:\Users\Matt\Projects\Project X\myapp-1_0\MyApp\templates\index.html, error at line 0
   The joined path (C:\) is located outside of the base path component (C:\Python35\lib\site-packages\django\contrib\admin\static)   1 : {% extends 'base.html' %}
   2 : {% block title %}MyApp 1.0{% endblock %}
   3 : 
   4 : {% block content %}
   5 : <div id="content">
   6 : </div>  
   7 : {% endblock %}

Traceback:

File "C:\Python35\lib\site-packages\django\core\handlers\exception.py" in inner
  39.             response = get_response(request)

File "C:\Python35\lib\site-packages\django\core\handlers\base.py" in _get_response
  217.                 response = self.process_exception_by_middleware(e, request)

File "C:\Python35\lib\site-packages\django\core\handlers\base.py" in _get_response
  215.                 response = response.render()

File "C:\Python35\lib\site-packages\django\template\response.py" in render
  109.             self.content = self.rendered_content

File "C:\Python35\lib\site-packages\django\template\response.py" in rendered_content
  86.         content = template.render(context, self._request)

File "C:\Python35\lib\site-packages\django\template\backends\django.py" in render
  66.             return self.template.render(context)

File "C:\Python35\lib\site-packages\django\template\base.py" in render
  208.                     return self._render(context)

File "C:\Python35\lib\site-packages\django\template\base.py" in _render
  199.         return self.nodelist.render(context)

File "C:\Python35\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Python35\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Python35\lib\site-packages\django\template\loader_tags.py" in render
  174.         return compiled_parent._render(context)

File "C:\Python35\lib\site-packages\django\template\base.py" in _render
  199.         return self.nodelist.render(context)

File "C:\Python35\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Python35\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Python35\lib\site-packages\pipeline\templatetags\pipeline.py" in render
  140.         return self.render_compressed(package, package_name, 'css')

File "C:\Python35\lib\site-packages\pipeline\templatetags\pipeline.py" in render_compressed
  72.                                                   package_type)

File "C:\Python35\lib\site-packages\pipeline\templatetags\pipeline.py" in render_compressed_sources
  104.             paths = packager.compile(package.paths)

File "C:\Python35\lib\site-packages\pipeline\packager.py" in paths
  34.         return [path for path in self.sources

File "C:\Python35\lib\site-packages\pipeline\packager.py" in sources
  27.                     if path not in paths and find(path):

File "C:\Python35\lib\site-packages\django\contrib\staticfiles\finders.py" in find
  250.         result = finder.find(path, all=all)

File "C:\Python35\lib\site-packages\django\contrib\staticfiles\finders.py" in find
  160.             match = self.find_in_app(app, path)

File "C:\Python35\lib\site-packages\django\contrib\staticfiles\finders.py" in find_in_app
  174.             if storage.exists(path):

File "C:\Python35\lib\site-packages\django\core\files\storage.py" in exists
  394.         return os.path.exists(self.path(name))

File "C:\Python35\lib\site-packages\django\core\files\storage.py" in path
  407.         return safe_join(self.location, name)

File "C:\Python35\lib\site-packages\django\utils\_os.py" in safe_join
  78.             'component ({})'.format(final_path, base_path))

Exception Type: SuspiciousFileOperation at /MyApp/
Exception Value: The joined path (C:\) is located outside of the base path component (C:\Python35\lib\site-packages\django\contrib\admin\static)

附录 B:这是完整的设置

ABSOLUTE_URL_OVERRIDES  
{}
ADMINS  
[]
ALLOWED_HOSTS   
[]
APPEND_SLASH    
True
AUTHENTICATION_BACKENDS 
['django.contrib.auth.backends.ModelBackend']
AUTH_PASSWORD_VALIDATORS    
'********************'
AUTH_USER_MODEL 
'auth.User'
CACHES  
{'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
CACHE_MIDDLEWARE_ALIAS  
'default'
CACHE_MIDDLEWARE_KEY_PREFIX 
'********************'
CACHE_MIDDLEWARE_SECONDS    
600
CSRF_COOKIE_AGE 
31449600
CSRF_COOKIE_DOMAIN  
None
CSRF_COOKIE_HTTPONLY    
False
CSRF_COOKIE_NAME    
'csrftoken'
CSRF_COOKIE_PATH    
'/'
CSRF_COOKIE_SECURE  
False
CSRF_FAILURE_VIEW   
'django.views.csrf.csrf_failure'
CSRF_HEADER_NAME    
'HTTP_X_CSRFTOKEN'
CSRF_TRUSTED_ORIGINS    
[]
DATABASES   
{'default': {'ATOMIC_REQUESTS': False,
             'AUTOCOMMIT': True,
             'CONN_MAX_AGE': 0,
             'ENGINE': 'django.db.backends.postgresql',
             'HOST': '127.0.0.1',
             'NAME': 'FooDB',
             'OPTIONS': {},
             'PASSWORD': '********************',
             'PORT': '5432',
             'TEST': {'CHARSET': None,
                      'COLLATION': None,
                      'MIRROR': None,
                      'NAME': None},
             'TIME_ZONE': None,
             'USER': 'postgres'}}
DATABASE_ROUTERS    
[]
DATA_UPLOAD_MAX_MEMORY_SIZE 
2621440
DATA_UPLOAD_MAX_NUMBER_FIELDS   
1000
DATETIME_FORMAT 
'N j, Y, P'
DATETIME_INPUT_FORMATS  
['%Y-%m-%d %H:%M:%S',
 '%Y-%m-%d %H:%M:%S.%f',
 '%Y-%m-%d %H:%M',
 '%Y-%m-%d',
 '%m/%d/%Y %H:%M:%S',
 '%m/%d/%Y %H:%M:%S.%f',
 '%m/%d/%Y %H:%M',
 '%m/%d/%Y',
 '%m/%d/%y %H:%M:%S',
 '%m/%d/%y %H:%M:%S.%f',
 '%m/%d/%y %H:%M',
 '%m/%d/%y']
DATE_FORMAT 
'N j, Y'
DATE_INPUT_FORMATS  
['%Y-%m-%d',
 '%m/%d/%Y',
 '%m/%d/%y',
 '%b %d %Y',
 '%b %d, %Y',
 '%d %b %Y',
 '%d %b, %Y',
 '%B %d %Y',
 '%B %d, %Y',
 '%d %B %Y',
 '%d %B, %Y']
DEBUG   
True
DEBUG_PROPAGATE_EXCEPTIONS  
False
DECIMAL_SEPARATOR   
'.'
DEFAULT_CHARSET 
'utf-8'
DEFAULT_CONTENT_TYPE    
'text/html'
DEFAULT_EXCEPTION_REPORTER_FILTER   
'django.views.debug.SafeExceptionReporterFilter'
DEFAULT_FILE_STORAGE    
'django.core.files.storage.FileSystemStorage'
DEFAULT_FROM_EMAIL  
'webmaster@localhost'
DEFAULT_INDEX_TABLESPACE    
''
DEFAULT_TABLESPACE  
''
DISALLOWED_USER_AGENTS  
[]
DJANGO_ROOT 
'C:\\Users\\Matt\\Projects\\MyProject\\myapp-1_0'
EMAIL_BACKEND   
'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST  
'localhost'
EMAIL_HOST_PASSWORD 
'********************'
EMAIL_HOST_USER 
''
EMAIL_PORT  
25
EMAIL_SSL_CERTFILE  
None
EMAIL_SSL_KEYFILE   
'********************'
EMAIL_SUBJECT_PREFIX    
'[Django] '
EMAIL_TIMEOUT   
None
EMAIL_USE_SSL   
False
EMAIL_USE_TLS   
False
FILE_CHARSET    
'utf-8'
FILE_UPLOAD_DIRECTORY_PERMISSIONS   
None
FILE_UPLOAD_HANDLERS    
['django.core.files.uploadhandler.MemoryFileUploadHandler',
 'django.core.files.uploadhandler.TemporaryFileUploadHandler']
FILE_UPLOAD_MAX_MEMORY_SIZE 
2621440
FILE_UPLOAD_PERMISSIONS 
None
FILE_UPLOAD_TEMP_DIR    
None
FIRST_DAY_OF_WEEK   
0
FIXTURE_DIRS    
[]
FORCE_SCRIPT_NAME   
None
FORMAT_MODULE_PATH  
None
IGNORABLE_404_URLS  
[]
INSTALLED_APPS  
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'pipeline',
 'rest_framework',
 'MyApp']
INTERNAL_IPS    
[]
LANGUAGES   
[('af', 'Afrikaans'),
 ('ar', 'Arabic'),
 ('ast', 'Asturian'),
 ('az', 'Azerbaijani'),
 ('bg', 'Bulgarian'),
 ('be', 'Belarusian'),
 ('bn', 'Bengali'),
 ('br', 'Breton'),
 ('bs', 'Bosnian'),
 ('ca', 'Catalan'),
 ('cs', 'Czech'),
 ('cy', 'Welsh'),
 ('da', 'Danish'),
 ('de', 'German'),
 ('dsb', 'Lower Sorbian'),
 ('el', 'Greek'),
 ('en', 'English'),
 ('en-au', 'Australian English'),
 ('en-gb', 'British English'),
 ('eo', 'Esperanto'),
 ('es', 'Spanish'),
 ('es-ar', 'Argentinian Spanish'),
 ('es-co', 'Colombian Spanish'),
 ('es-mx', 'Mexican Spanish'),
 ('es-ni', 'Nicaraguan Spanish'),
 ('es-ve', 'Venezuelan Spanish'),
 ('et', 'Estonian'),
 ('eu', 'Basque'),
 ('fa', 'Persian'),
 ('fi', 'Finnish'),
 ('fr', 'French'),
 ('fy', 'Frisian'),
 ('ga', 'Irish'),
 ('gd', 'Scottish Gaelic'),
 ('gl', 'Galician'),
 ('he', 'Hebrew'),
 ('hi', 'Hindi'),
 ('hr', 'Croatian'),
 ('hsb', 'Upper Sorbian'),
 ('hu', 'Hungarian'),
 ('ia', 'Interlingua'),
 ('id', 'Indonesian'),
 ('io', 'Ido'),
 ('is', 'Icelandic'),
 ('it', 'Italian'),
 ('ja', 'Japanese'),
 ('ka', 'Georgian'),
 ('kk', 'Kazakh'),
 ('km', 'Khmer'),
 ('kn', 'Kannada'),
 ('ko', 'Korean'),
 ('lb', 'Luxembourgish'),
 ('lt', 'Lithuanian'),
 ('lv', 'Latvian'),
 ('mk', 'Macedonian'),
 ('ml', 'Malayalam'),
 ('mn', 'Mongolian'),
 ('mr', 'Marathi'),
 ('my', 'Burmese'),
 ('nb', 'Norwegian Bokmål'),
 ('ne', 'Nepali'),
 ('nl', 'Dutch'),
 ('nn', 'Norwegian Nynorsk'),
 ('os', 'Ossetic'),
 ('pa', 'Punjabi'),
 ('pl', 'Polish'),
 ('pt', 'Portuguese'),
 ('pt-br', 'Brazilian Portuguese'),
 ('ro', 'Romanian'),
 ('ru', 'Russian'),
 ('sk', 'Slovak'),
 ('sl', 'Slovenian'),
 ('sq', 'Albanian'),
 ('sr', 'Serbian'),
 ('sr-latn', 'Serbian Latin'),
 ('sv', 'Swedish'),
 ('sw', 'Swahili'),
 ('ta', 'Tamil'),
 ('te', 'Telugu'),
 ('th', 'Thai'),
 ('tr', 'Turkish'),
 ('tt', 'Tatar'),
 ('udm', 'Udmurt'),
 ('uk', 'Ukrainian'),
 ('ur', 'Urdu'),
 ('vi', 'Vietnamese'),
 ('zh-hans', 'Simplified Chinese'),
 ('zh-hant', 'Traditional Chinese')]
LANGUAGES_BIDI  
['he', 'ar', 'fa', 'ur']
LANGUAGE_CODE   
'en-us'
LANGUAGE_COOKIE_AGE 
None
LANGUAGE_COOKIE_DOMAIN  
None
LANGUAGE_COOKIE_NAME    
'django_language'
LANGUAGE_COOKIE_PATH    
'/'
LOCALE_PATHS    
[]
LOGGING 
{}
LOGGING_CONFIG  
'logging.config.dictConfig'
LOGIN_REDIRECT_URL  
'/accounts/profile/'
LOGIN_URL   
'/accounts/login/'
LOGOUT_REDIRECT_URL 
None
MANAGERS    
[]
MEDIA_ROOT  
''
MEDIA_URL   
''
MESSAGE_STORAGE 
'django.contrib.messages.storage.fallback.FallbackStorage'
MIDDLEWARE  
['django.middleware.security.SecurityMiddleware',
 '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']
MIDDLEWARE_CLASSES  
['django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware']
MIGRATION_MODULES   
{}
MONTH_DAY_FORMAT    
'F j'
NUMBER_GROUPING 
0
PASSWORD_HASHERS    
'********************'
PASSWORD_RESET_TIMEOUT_DAYS 
'********************'
PIPELINE    
{'BROWSERFIFY_ARGS': '-t babelify',
 'COMPILERS': {'pipeline_browserify.compiler.BrowserifyCompiler'},
 'CSS_COMPRESSOR': {'pipeline.compressors.NoopCompressor'},
 'JAVASCRIPT': {'myapp_js': {'output_filename': 'js/myapp_js.js',
                               'source_filenames': ('js/bower_components/jquery/dist/jquery.min.js',
                                                    'js/bower_components/react/JSXTransformer.js',
                                                    'js/bower_components/react/react-with-addons.js',
                                                    'js/app.browserify.js')}},
 'JS_COMPRESSOR': {'pipeline.compressors.uglifyjs.UglifyJSCompressor'},
 'STYLESHEETS': {'myapp_css': {'output_filename': 'css/myapp_css.css',
                                 'source_filenames': 'css/style.css'}}}
PREPEND_WWW 
False
ROOT_URLCONF    
'MyApp.urls'
SECRET_KEY  
'********************'
SECURE_BROWSER_XSS_FILTER   
False
SECURE_CONTENT_TYPE_NOSNIFF 
False
SECURE_HSTS_INCLUDE_SUBDOMAINS  
False
SECURE_HSTS_SECONDS 
0
SECURE_PROXY_SSL_HEADER 
None
SECURE_REDIRECT_EXEMPT  
[]
SECURE_SSL_HOST 
None
SECURE_SSL_REDIRECT 
False
SERVER_EMAIL    
'root@localhost'
SESSION_CACHE_ALIAS 
'default'
SESSION_COOKIE_AGE  
1209600
SESSION_COOKIE_DOMAIN   
None
SESSION_COOKIE_HTTPONLY 
True
SESSION_COOKIE_NAME 
'sessionid'
SESSION_COOKIE_PATH 
'/'
SESSION_COOKIE_SECURE   
False
SESSION_ENGINE  
'django.contrib.sessions.backends.db'
SESSION_EXPIRE_AT_BROWSER_CLOSE 
False
SESSION_FILE_PATH   
None
SESSION_SAVE_EVERY_REQUEST  
False
SESSION_SERIALIZER  
'django.contrib.sessions.serializers.JSONSerializer'
SETTINGS_MODULE 
'myapp-1_0.MyApp.settings'
SHORT_DATETIME_FORMAT   
'm/d/Y P'
SHORT_DATE_FORMAT   
'm/d/Y'
SIGNING_BACKEND 
'django.core.signing.TimestampSigner'
SILENCED_SYSTEM_CHECKS  
[]
SITE_NAME   
'myapp-1_0'
SITE_ROOT   
'C:\\Users\\Matt\\Projects\\MyProject'
STATICFILES_DIRS    
()
STATICFILES_FINDERS 
('django.contrib.staticfiles.finders.FileSystemFinder',
 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
 'pipeline.finders.PipelineFinder')
STATICFILES_STORAGE 
'pipeline.storage.PipelineStorage'
STATIC_ROOT 
'C:\\Users\\Matt\\Projects\\MyProject\\static'
STATIC_URL  
'/static/'
TEMPLATES   
[{'APP_DIRS': True,
  'BACKEND': 'django.template.backends.django.DjangoTemplates',
  'DIRS': ['templates'],
  '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']}}]
TEST_NON_SERIALIZED_APPS    
[]
TEST_RUNNER 
'django.test.runner.DiscoverRunner'
THOUSAND_SEPARATOR  
','
TIME_FORMAT 
'P'
TIME_INPUT_FORMATS  
['%H:%M:%S', '%H:%M:%S.%f', '%H:%M']
TIME_ZONE   
'America/Chicago'
USE_ETAGS   
False
USE_I18N    
True
USE_L10N    
True
USE_THOUSAND_SEPARATOR  
False
USE_TZ  
True
USE_X_FORWARDED_HOST    
False
USE_X_FORWARDED_PORT    
False
WSGI_APPLICATION    
'MyApp.wsgi.application'
X_FRAME_OPTIONS 
'SAMEORIGIN'
YEAR_MONTH_FORMAT   
'F Y'
4

0 回答 0