So, I have PyCharm 2017.2.3, and Python 3.6, and Django 1.11. while practicing on the test project, I tried to render to my index.html
in view.py
under my app. Below is the piece of code that I am talking about:
def index(request):
db_Conn = Album.objects.all()
template = loader.get_template('/music/index.html')
context = {
'db_Conn': db_Conn,
}
return HttpResponse(template.re)
Inside return HttpResponse
, I can get until template, but when I use a period after template to use the render()
sub-function, I do not get any suggestion from PyCharm for render()
instead, I could see two other functions which not relevant to my post.
Can sombody help me on this. My learning is halted due to this.
Try this. I assume music is app name, so your template file should be in, music/templates/index.html
from django.shortcuts import render
from django.utils import timezone
def index(request):
return render(request, 'index.html', {'start_date':timezone.now()})
If not understood refer to this repo
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.