5
I am using the visual studio community and created a web project with Django, but when making the homepage, is generating me this code:
And the code I have is this:
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title>
<link rel="stylesheet" type="text/css" href="{% static 'app/content/materialize.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'app/content/app.css' %}" />
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
</head>
<body>
Does anyone know why while running, he does it? I trash html?
this is creating a space on my page that should not have.
code that renders:
def home(request):
"""Renders the home page."""
assert isinstance(request, HttpRequest)
return render(
request,
'app/index.html',
{
'title':'Home Page',
'year':datetime.now().year,
}
)
Checks if your html document (the template file) has any null characters (with Regex in an advanced text editor you can find by typing
\0
), can be this. Also check if you saved all documents in UTF8.– Guilherme Nascimento
@Guilhermenascimento, the documents are in utf-8 and have no null character, I tried to leave the document totally blank with nothing, nor the basic html tag and the same thing...
– MeuChapeu
Are you sure the template being rendered is yours? I don’t know how Visual Studio does it, but maybe it’s rendering a template of its own and including its like contents page (i.e. putting everything in the body of the "parent" template). What is the code that renders and returns this template? (i.e. the view)
– mgibsonbr
@mgibsonbr, I added in the question.. I find it strange because the model that comes in visual studio works right, it doesn’t break html, and I just changed the content of the home page and start to give these crazy...
– MeuChapeu
You better give
CTRL+U
... The new Chrome update shows some strange stops onConsole
– Wallace Maxters
Did you use Windows Notepad to make this issue? (see that answer in Soen, ask me if you want more details) By the way, there is a difference between the HTML actually received from the server (which you see by the "view source code" function of the browser) and the DOM generated from it (which you see by the "inspect element" or similar function). Your screenshot seems to me the second case. See what is actually being generated, if the strange content is coming within the
body
(doubt, but may be) or at the beginning of the file (I think most likely).– mgibsonbr
@mgibsonbr, that’s right, I changed the codiffication to utf-8 without BOM and it works... now it’s doubtful.. will I have to do it for the next files I’ll create?
– MeuChapeu
@Meuchapeu I’m afraid so... Unless you use some other text editor that you use (or can be set to) by default UTF-8 without BOM.
– mgibsonbr