Forums

django tags is not working django1.8/python3.5

django tags such like "{% load staticfiles %}" become text on my website.

I had tried re-building virtual environment. but it's used. I have no idea where is wrong.

another question: Is "manage.py collectstatic" necessary? if I have built my own static folder.

Help my poor English can let you understand. THANKS.

Hi there,

If django tags are appearing in your website, my guess would be that you're not rendering your templates, just returning them as static files instead. You should use Django views and the render function. Maybe take a look at a django tutorial? djangogirls is the most beginner-friendly. Or the official django tutorial is fine, a bit of a steeper learning curve.

The static files system is for "assets", things like images, css, javascript. Not usually for plain HTML. We have a guide here

hi harry, thanks for you reply. I'm sorry for my depiction being not clear. My website is finished in local host and it works successfully. But when I followed the tutorial djangogirls to deploy my website, the problem appear.

You're serving your root page as a static file, so it's being delivered as-is.

hi glenn, do you mean the third step of here ? if so, I have done.

In my setting.py

STATIC_ROOT = '/home/collegescore/mysite/templates/static/'
STATIC_URL= '/static/'

STATICFILES_DIRS = (
("js", os.path.join(STATIC_ROOT,'js')),
("css", os.path.join(STATIC_ROOT,'css')),
("images", os.path.join(STATIC_ROOT,'images')),
("fonts", os.path.join(STATIC_ROOT,'fonts')),
("datas", os.path.join(STATIC_ROOT,'datas'))
)

In the Static Files section

URL Directory   
/           /home/collegescore/mysite/templates/hello_world.html     
/static/    /home/collegescore/mysite/templates/static

"hello_world.html" is my root page.

Yes. The Static file entry for / is serving hello_world.py as a static file, so you see the template tags because they are in the file.