Answer the question
In order to leave comments, you need to log in
Question about outputting Django content to HTML?
There is an expanded page. However, everything that is displayed in it is specified in HTML (pictures, text, etc.)
How to output content from the database?
https://codeshare.io/ZwwR8 here is an attempt to do this, but it did not work out. :(
Answer the question
In order to leave comments, you need to log in
Well, pass data to the context in views, and actually display this data in templates.
In views.py, you pass some data to the context:
from django.http import Http404
from django.shortcuts import render
from models import КакаяТоМодель
def my_view(request, какой_то_id):
try:
my_obj = КакаяТоМодель.objects.get(pk=какой_то_id)
except КакаяТоМодель.DoesNotExist:
raise Http404(u"Объект КакаяТоМодель с id={id} отсутствует в базе".format(id=какой_то_id))
какая_то_переменная = ФункцияДляПолучениЧегоТоИзБазы()
return render(request, 'какой_то_темплейт.html', {'my_obj': my_obj, 'my_var': какая_то_переменная})
...
{{ my_obj.какое_то_поле }}
{{ my_obj.какое_то_поле }}
....
{{ my_var }}
....
class BannerView(View):
model = Banner
template_name = 'home.html'
def get_queryset(self):
return Banner.objects.all()
class BannerView(ListView):
model = Banner
template_name = 'home.html'
....
{% for obj in object_list %}
{{ obj.какое_то поле }}
{% endfor %}
....
class HomePage(TemplateView):
template_name = 'home.html'
class HomePage(TemplateView):
template_name = 'home.html'
def get_context_data(self, *args, **kwargs):
context = super(HomePage, self).get_context_data(*args, **kwargs)
context['имя_какой_то_переменной_для_темплейта'] = ФункцияДляПолученияКакихТоДанных()
return context
....
{{ имя_какой_то_переменной_для_темплейта }}
....
How do you start the server? what version of junga?
Did you put the statics in the right directories?
You need to understand that static and media files are different things. Static is css + js + icon - what is always displayed on the site, it is usually stored on the file system and is given to the web server (nginx or apache)
in the production - also on the file system.
More details - djbook.ru/rel1.9/howto/static-files/index.html and djbook.ru/rel1.9/topics/files.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question