3

I set a Django view+url that points to a HTML form. The HTML file is linked to two stylesheets using @import. When I visit the page, terminal tells me that GET requests are sent to the two CSS files, but the page is rendered as pure HTML without any CSS.

Here's the code that links to the stylesheet in the HTML file:

<head>
<title>Register</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style>
    @import url("./css/common.css");
    @import url("./css/desktop.css");
</style>
</head>

Here's the relevant code snippet from the view:

return render_to_response("signup.html", {'form': form,}, RequestContext(request))

Will post more code if asked for it. This is really bugging me. Thanks in advance!

  • 1
    And are those two GET requests successfully served, or do they result in 404s? What happens if you go to those addresses manually? And what happens if you drop the annoying `@import` and reference the stylesheets directly with `` tags, like everyone else? – Daniel Roseman Dec 04 '12 at 11:12
  • You don't you use `` tags to reference stylesheets? – arulmr Dec 04 '12 at 11:15
  • @Daniel: Doesn't work with either. GET requests are successfully served. Can't go to the addresses manually because I haven't defined URL paths for them in the Django urls file. Should i? – Akhil Mallavarapu Dec 04 '12 at 11:32
  • What? That answer makes no sense. If GET requests are being successfully served, then that means you can go directly to the addresses manually by typing the same address in your browser. What happens when you do that? – Daniel Roseman Dec 04 '12 at 11:49
  • Huh... just typed the addresses manually. Both the CSS files give me the same HTML page without the CSS, the one I normally get. That's odd. – Akhil Mallavarapu Dec 04 '12 at 11:55
  • Actually, no matter what I put after /signup/ it gives me the same page. It seems to just look at signup and then direct me to signup.html. – Akhil Mallavarapu Dec 04 '12 at 12:06
  • OH CRAP! Forgot the '$' in the URLs file. No wonder. Now the GET requests to the CSS files give me a 404. – Akhil Mallavarapu Dec 04 '12 at 12:08
  • How do I specify the path to the CSS file? I've tried absolute and relative but neither seem to work. – Akhil Mallavarapu Dec 04 '12 at 12:14

2 Answers2

0

You could try putting the entire css file contents in between the style tags and see if that works. Then you know that it has a problem importing the css files and your path is wrong. Just a suggestion

topcat3
  • 2,561
  • 6
  • 33
  • 57
  • It works if I put the entire CSS in the HTML page! But I'm pretty sure I have the path right because, as I mentioned in the question, terminal tells me that it sends a GET request to the CSS files, and the terminal text isn't highlighted (which means, and please correct me if I'm wrong, it did it without any errors). EDIT: It gives me a HTTP status message: 200 1450, which means successful. – Akhil Mallavarapu Dec 04 '12 at 11:26
  • and if you debug with firebug you can see the css or it is just blank between the – topcat3 Dec 04 '12 at 11:33
  • see the answer with 3 upvotes here http://stackoverflow.com/questions/9026409/django-site-in-developement-css-not-loading-for-all-pages . It should help you – topcat3 Dec 04 '12 at 11:38
0

can you please defined where is your current file location in which you import css because you trying this

<style>
    @import url("./css/common.css");
    @import url("./css/desktop.css");
</style>

in this case your css in is upward then your html page ???? let me know ???

The Mechanic
  • 2,301
  • 1
  • 26
  • 37