How does collect static work?

Nanor

I don't fundamentally understand how manage.py collectstatic works. The idea I had was you have the path

project/app/static/app/base.css 

and run collectstatic and it copies them to a /staticfiles/ folder which can then be accessed by {{STATIC_URL}}. I've tried this and it doesn't seem to find base.css.

Here are my variables for reference:

basepath = os.path.split(os.path.abspath(__file__))[0]    
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(basepath, 'staticfiles')
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}base.css" />

Which all leads up to a 404 error when trying to get the stylesheet:

"GET /base.css HTTP/1.1" 404 2255
dm03514

It seems collectstatic is copying it over fine.

I think you just need to use the {% static "base.css" %} template tag instead of trying to access the STATIC_URL variable

i don't think STATIC_URL is available in the template scope.

you COULD access it doing something like

from django.conf import settings

settings.STATIC_URL

but {% static %} tag does this for you. It seems the version of django is important 1.5 looks like it uses the {% static %} tag, but early versions look like they support STATIC_URL when you have RequestContext registered.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Why and how does this work?

분류에서Dev

How does this work in javascript

분류에서Dev

endturnwithnextparticipants, how does it work?

분류에서Dev

How does SimpleCORSFilter work?

분류에서Dev

Phonegap how does it work?

분류에서Dev

Does monolithic link-time optimization work with static libraries?

분류에서Dev

How does "newElements" work in Javascript?

분류에서Dev

How does scanr work? Haskell

분류에서Dev

how does readyRead() work in Qt?

분류에서Dev

How does this pointer typecasting work?

분류에서Dev

How does shared hosting work?

분류에서Dev

How does ServiceNameQuery work in AngularJS

분류에서Dev

How does the INTERVAL datatype work?

분류에서Dev

How does file compression work?

분류에서Dev

How does Windows API work?

분류에서Dev

How does -Infinity actually work?

분류에서Dev

how does int*& variableName work ?

분류에서Dev

How does 'telnet localhost' work?

분류에서Dev

How to make this code dynamic and work with a CMS (not static content)?

분류에서Dev

How does return work for a function local variable?

분류에서Dev

How does ForkJoinPool#awaitQuiescence actually work?

분류에서Dev

How does * to access pointers of variables or arrays work?

분류에서Dev

How does Xojo UI rendering for desktop work?

분류에서Dev

How does this implementation of array intersection work?

분류에서Dev

How does Gradient.Evaluate work internally?

분류에서Dev

How Does Initalizing a Javascript Modal Work in Materializecss?

분류에서Dev

How does Eclipse web service explorer work?

분류에서Dev

How does the --fuzzy option for rsync work?

분류에서Dev

How does Google Chrome's Sandbox work?