开发者

Importing HTML in Django

开发者 https://www.devze.com 2023-02-27 00:14 出处:网络
I have imported an HTML file which displays fine -- def index(request): html = open(\'index.html\') return HttpResponse(html)

I have imported an HTML file which displays fine --

def index(request):
    html = open('index.html')
    return HttpResponse(html)

However, the CSS import and image references are not working (e开发者_开发问答ven though the files are there and it works when I test the file outside of Django). What do I need to do so that the imports/references within the HTML work? Thank you.


Not sure if you've read through Django's docs, but I think what you probably want is this:

from django.shortcuts import render_to_response

def index(request):
    return render_to_response('index.html')

EDIT: Take a read through this: http://docs.djangoproject.com/en/dev/intro/tutorial03/


I have a feeling that your problem may be related to media and/or static file hosting. If you view the page source and click on your links, do they go to Django's 404?

How are you hosting your files?

If you are just working on development on your local machine take a look at the docs for static file hosting.

Also- if there isn't any logic in your view, other than html rendering, check out direct_to_teplate generic view which allows you to go straight from your urls.py to a template without writing a view. Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消