简体   繁体   中英

Issue while integrating bootstrap template in a django project

I am trying to integrate bootstrap template with one of my Django project. I mostly succeeded in doing so and was able to render all the images and other stuff of the template to my django project. But the actual formatting of the template was lost while integrating. I found the below error while doing so, need help to understand and find remedy to the error. Below is the error from my cmd.

 File "C:\Users\DELL\Anaconda3\lib\site-packages\django\utils\_os.py", line 46, in safe_join
    'component ({})'.format(final_path, base_path))
django.core.exceptions.SuspiciousFileOperation: The joined path (S:\stackpath.bootstrapcdn.com\bootstrap\4.4.1\js\bootstrap.min.js) is located outside of the base path component (C:\Users\DELL\community@with_final_template 7 Feb 2020\static)
[09/Feb/2020 10:46:44] "GET /static/https%3A/stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js HTTP/1.1" 500 59
Not Found: /favicon.ico
[09/Feb/2020 10:46:44] "GET /favicon.ico HTTP/1.1" 404 6333

settings.py

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

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

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

We need to see your template code to be sure, but it seems that in your template you have done this:

<script src="{% static 'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js` %}"></script>

... which is invalid. The static template tag can only be used for assets that are stored in your static directory. External libraries like this should just be referenced as a regular URL:

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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