with open(path_in, 'w+') as read_file:
read_file.write('something')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'builtins': 'app.templatetags.extratags' # <<<<<<<<<<<<<<<
},
},
]
def get_lenta_elem(request):
items = Product.objects.all()
return {'items': items }
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
# custom context processor
'путь_к_файлу.навание_метода' # <<<<<<<<<<<<<
],
},
},
]
<input type="radio" name="choice" value="choice1">
<input type="radio" name="choice" value="choice2">
<input type="radio" name="choice" value="choice3">
choice = request.POST['choice']
print(choice)
>>> choice1
choice = request.POST.get('choice', None)
if choice:
делать ваш код
else:
вы не выбрали батон
class SupplyAdmin(admin.ModelAdmin):
available_fields = ('name', 'field1', 'field2')
hidden_fields = ('field3',)
def get_form(self, request, obj, **kwargs):
if request.user.username == 'example@example.com':
self.fields = self.available_fields + self.hidden_fields
else:
self.fields = self.available_fields
return super(SupplyAdmin, self).get_form(request, obj, **kwargs)
class ItemAttributeValue(models.Model):
att1 = .....
att2 = .....
item = models.ForeignKey(ItemAttribute, related_name='attribute')
characteristics = ItemAttribute.objects.get(category=3)
{% for i in characteristics %}
{{ i.name}}
...
{{ i.attribute.att1}}
...
{% endfor %}