Project

General

Profile

Segnalazione #54

Problema con static_root

Added by Christopher R. Gabriel almost 8 years ago. Updated almost 8 years ago.

Status:
Chiuso
Priority:
Normale
Target version:
Start date:
06/28/2016
Due date:
% Done:

0%

Estimated time:
Resolution:
fixed

Description

I vari template html sono stati modificati per usare un path hardcoded per gli static file, mentre questo deve usare il templatetag {{ static }}

Associated revisions

Revision a2ff5865 (diff)
Added by Marco Marinello almost 8 years ago

Migrazione a tag static
refs #54

History

#1

Updated by Christopher R. Gabriel almost 8 years ago

Vedi ad esempio commit 8a3146df577ce640e7b82c47042efcf5c41ff502

#2

Updated by Marco Marinello almost 8 years ago

  • Status changed from Nuovo to In elaborazione
  • Assignee changed from Marco Marinello to Christopher R. Gabriel

Ho provato a modificare il login con il tag {{static}} per gli indirizzi statici dello stile e la pagina viene caricata non stilizzata. Questo è il debug di Django

[28/Jun/2016 10:31:23] "GET /login/?next=/ HTTP/1.1" 200 1504
[28/Jun/2016 10:31:23] "GET /css/login.css HTTP/1.1" 404 3560
[28/Jun/2016 10:31:23] "GET /css/bootstrap.min.css HTTP/1.1" 404 3584
[28/Jun/2016 10:31:23] "GET /js/bootstrap.min.js HTTP/1.1" 404 3578
[28/Jun/2016 10:31:23] "GET /js/jquery-1.10.2.min.js HTTP/1.1" 404 3590
[28/Jun/2016 10:31:23] "GET /js/bootstrap.min.js HTTP/1.1" 404 3578

#3

Updated by Christopher R. Gabriel almost 8 years ago

  • Assignee changed from Christopher R. Gabriel to Marco Marinello

Perche' probabilmente hai settings.STATIC_ROOT vuoto...

cfr. https://docs.djangoproject.com/en/1.9/howto/static-files/

#4

Updated by Marco Marinello almost 8 years ago

  • Assignee changed from Marco Marinello to Christopher R. Gabriel

settings.py [131:142]

# Static files (CSS, JavaScript, Images)

# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = '/static'

STATICFILES_DIRS = [

    # Don't forget to use absolute paths, not relative paths.

    os.path.join(BASE_DIR, "static"),

]

STATICFILES_FINDERS = [

    'django.contrib.staticfiles.finders.FileSystemFinder',

    'django.contrib.staticfiles.finders.AppDirectoriesFinder',

]

STATIC_ROOT e _URL sono configurati (correttamente).

#5

Updated by Christopher R. Gabriel almost 8 years ago

  • Assignee changed from Christopher R. Gabriel to Marco Marinello

Infatti, partendo da un checkout pulito del branch, funziona correttamente.

Probabilmente hai ancora il .pyc del settings_local ?

#6

Updated by Marco Marinello almost 8 years ago

  • Assignee changed from Marco Marinello to Christopher R. Gabriel

Controllato, nessun .pyc .
Ho clonato nuovamente in un'altra cartella il progetto ma continua a non funzionare (forse hai provato senza inserire {{static}} nel codice che io non ho ancora committato)

#7

Updated by Marco Marinello almost 8 years ago

  • Status changed from In elaborazione to Commenti
#8

Updated by Christopher R. Gabriel almost 8 years ago

  • Status changed from Commenti to In elaborazione
  • Assignee changed from Christopher R. Gabriel to Marco Marinello

Ovviamente no, il codice che ho provato e' corretto rispetto a quello che c'e' da fare.

cgabriel@filippone ~ $ GET -e http://localhost:8000/ | head -30 | tail -1
    <link href="/static/css/bootstrap.min.css" rel="stylesheet" />

e il template:

git diff login.html

diff --git a/pyhearing/templates/login.html b/pyhearing/templates/login.html
index 7bb93b1..1f5ad54 100755
--- a/pyhearing/templates/login.html
+++ b/pyhearing/templates/login.html
@@ -1,5 +1,5 @@
 {% load i18n %}
-
+{% load staticfiles %}
 <!DOCTYPE html>
 <html>
   <head>
@@ -10,7 +10,7 @@

     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-    <link href="/static/css/bootstrap.min.css" rel="stylesheet" />
+    <link href="{% static "css/bootstrap.min.css" %}" rel="stylesheet" />
     <link href="/static/css/login.css" rel="stylesheet" />
     <script src="/static/js/jquery-1.10.2.min.js"></script>

Leggi meglio il link della documentazione di cui sopra.

#9

Updated by Christopher R. Gabriel almost 8 years ago

  • Status changed from In elaborazione to Commenti
#10

Updated by Marco Marinello almost 8 years ago

  • Assignee changed from Marco Marinello to Christopher R. Gabriel

Nel template di prova utilizzi

{% static "css/bootstrap.min.css" %}

mentre nel primo messaggio era segnalato di utilizzare

{{static}}

Quale è corretto?

#11

Updated by Christopher R. Gabriel almost 8 years ago

  • Assignee changed from Christopher R. Gabriel to Marco Marinello

Scusa, "{{static}}" e' un mio typo di formattazione. E' il templatetag chiamato static, e si usa cosi'

{% static "path/to/file" %}

In ogni caso, fai riferimento alla documentazione che ti ho linkato, e' tutto scritto li'.

#12

Updated by Marco Marinello almost 8 years ago

  • Assignee changed from Marco Marinello to Christopher R. Gabriel

Risolto nel commit 78675f5c

#13

Updated by Christopher R. Gabriel almost 8 years ago

  • Status changed from Commenti to Chiuso
  • Resolution set to fixed

ok

Also available in: Atom PDF