2017-09-06 1 views
0

Je ne peux pas afficher mon image d'arrière-plan sur mon site Web. J'ai mis l'image d'arrière-plan dans mon style.css et lié cela dans "< style> fond: </style>".Django Templating - images d'arrière-plan Jinja

Je mets le {% load staticfiles%} au-dessus du style mais je suis assez sûr que c'est faux.

J'ai vérifié mes réglages et le réglage de STATIC_URL est STATIC_URL = '/ statique /'

Voici mon css

style.css

body { 
    background:slategray url("/personal/static/personal/images/background.gif")no-repeat right bottom; 
} 

Voici mon code html

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <!-- Required meta tags --> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> 
    <title>Mr. Hart</title> 


     <!-- Bootstrap CSS --> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous"> 

     <div class="row"> 
     <div class="col-md-8"> 
      <a href='/' style="display: inline-block; text-decoration-color: #1a8002;">Home</a> 
      <a href='/blog/' style="display: inline-block; text-decoration-color: green;"> Blog </a> 
      <a href='/Aboutme/' style="display: inline-block; text-decoration-color: green;"> About Me </a> 
      <a href='/stocks/' style="display: inline-block; text-decoration-color: green;"> My stock Tips </a> 
      <a href='/crypto/' style="display: inline-block; text-decoration-color: green;"> Crypto </a> 
     </div> 
     <div class="col-md-4">"This is where my contacts stack,github, stocktwits, twitter, all picture links "</div> 
     </div> 

     {% load staticfiles %} 
     <style type="text/css"> 
     html, 
     body { 
      background: url("{% static "/personal/style.css" %}") no-repeat center center fixed; 
      -webkit-background-size: cover; 
      -moz-background-size: cover; 
      -o-background-size: cover; 
      background-size: cover; 
     } 
    </style> 
    </head> 
+0

Salut vous essayez de rendre une image avec un CSS source que vous avez besoin d'une image ne un fichier CSS. voici votre problème de fond: url ("{% static" /personal/style.css "%}") essayez de charger votre image avec ASP ou JSP dunno essayez un arrière-plan: url (http: // domain/to/votre/image .jpg) salut –

+0

Je ne sais pas comment utiliser ASP ou JSP. J'ai essayé de pointer l'url directement sur l'image via le fond: url ("/ personal/static/personal/images/background.jpg") centre de centre de non-répétition fixe; en vain, toujours vide. – K2nice

+0

pour être sûr, essayez de charger sur votre navigateur l'image et copier coller l'URL avec "http: //" à l'arrière-plan: url (http/domain/to/votre/image.jpg) –

Répondre

0

Je pense qu'il ne trouve pas le fichier statique en raison de la s fouetter.

Essayons avec un fichier statique que nous savons exister:

$ ./manage.py findstatic admin/js/vendor/jquery/jquery.js 
Found 'admin/js/vendor/jquery/jquery.js' here: 
    /home/jpic/.local/lib/python3.6/site-packages/django/contrib/admin/static/admin/js/vendor/jquery/jquery.js 

Mais avec la barre oblique préfixage:

$ ./manage.py findstatic /admin/js/vendor/jquery/jquery.js 
Traceback (most recent call last): 
    File "./manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
    File "/home/jpic/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line 
    utility.execute() 
    File "/home/jpic/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 345, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/home/jpic/.local/lib/python3.6/site-packages/django/core/management/base.py", line 348, in run_from_argv 
    self.execute(*args, **cmd_options) 
    File "/home/jpic/.local/lib/python3.6/site-packages/django/core/management/base.py", line 399, in execute 
    output = self.handle(*args, **options) 
    File "/home/jpic/.local/lib/python3.6/site-packages/django/core/management/base.py", line 548, in handle 
    label_output = self.handle_label(label, **options) 
    File "/home/jpic/.local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/findstatic.py", line 22, in handle_label 
    result = finders.find(path, all=options['all']) 
    File "/home/jpic/.local/lib/python3.6/site-packages/django/contrib/staticfiles/finders.py", line 250, in find 
    result = finder.find(path, all=all) 
    File "/home/jpic/.local/lib/python3.6/site-packages/django/contrib/staticfiles/finders.py", line 160, in find 
    match = self.find_in_app(app, path) 
    File "/home/jpic/.local/lib/python3.6/site-packages/django/contrib/staticfiles/finders.py", line 174, in find_in_app 
    if storage.exists(path): 
    File "/home/jpic/.local/lib/python3.6/site-packages/django/core/files/storage.py", line 294, in exists 
    return os.path.exists(self.path(name)) 
    File "/home/jpic/.local/lib/python3.6/site-packages/django/core/files/storage.py", line 307, in path 
    return safe_join(self.location, name) 
    File "/home/jpic/.local/lib/python3.6/site-packages/django/utils/_os.py", line 78, in safe_join 
    'component ({})'.format(final_path, base_path)) 
django.core.exceptions.SuspiciousFileOperation: The joined path (/admin/js/vendor/jquery/jquery.js) is located outside of the base path component (/home/jpic/src/django-autocomplete-light/test_project/linked_data/static) 

Voir la documentation officielle et certains articles de blog: