@method_decorator(csrf_exempt, name='dispatch')
class Registration(View):
def post(self, request, **kwargs):
data = json.loads(request.body)
if request.headers['Authorization'] != "Bearer TOKEN":
return HttpResponse("Unauthorized", status=401)
result = {
"result": True,
}
psw = passwordGenerator(10)
phone = phone_clean(data['phone'])
user, created = User.objects.get_or_create(
username=phone,
first_name=data['first_name'],
last_name=data['last_name'],
)
if created:
n = [i for i in a if i.isdigit()]
n = "".join(n)
d = datetime.datetime.strptime(n,"%Y%m%d")
nd = [item for item in data['items'] if item["type"] != "charging_fee"]
import json
with open('1.json') as json_data:
data = json.load(json_data)
nd = [item for item in data['items'] if item["type"] != "charging_fee"]
with open('1.json', 'w') as outfile:
json.dump(nd, outfile)
class officeUsers(models.Model):
....
photo = models.ImageField(verbose_name='Фотография',
upload_to='photos/%Y/%m/%d',
blank=True)
....
<div class="user_img">
<img src="{% if user.photo %}{{ user.photo.url }}{% else %}{% static 'sysadmins/img/avatar.jpg' %}{% endif %}" alt="">
</div>