django

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 1: ordinal not in range(128)

本小妞迷上赌 提交于 2021-02-18 22:15:07
问题 I know there is existing title about this, but there question is different from mine. So here's my problem. I use context processor to display user name. It's working but my sentry detect an error yesterday. UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 1: ordinal not in range(128) Here is my code: def display_name(request): try: name = "{0} {1}".format(request.user.first_name, request.user.last_name) name = name.strip() if not name: name = request.user.username

no django app created when following the docker-compose tutorial

你。 提交于 2021-02-18 22:01:19
问题 I'm following the docker-compose tutorial, to try and figure out how to get a django app to deploy: http://docs.docker.com/compose/django/ And everything's going smoothly (the app even works!) but the django project folder composeexample isn't created in my local project directory. I'm left with a working "It Works!" page after running: $ docker-compose run web django-admin.py startproject composeexample . But I can't continue to edit the composeexample/settings.py , as the tutorial suggests:

Django template datetime.weekday name

时光毁灭记忆、已成空白 提交于 2021-02-18 22:00:59
问题 Is there a way to display the weekday of a datetime object in a template as the actual name of the weekday? Basically I want it to print Friday instead of 5 . 回答1: See the documentation for the built-in date filter. From there you'll see you need to use: l Day of the week, textual, long. 'Friday' 回答2: For clarity's sake, the template tag format character "l" (lower-case "L") can be used in the Django template like so: {{ object.some_date_field | date:"l" }} Django 1.8.2 回答3: You can also use:

Django template datetime.weekday name

时光总嘲笑我的痴心妄想 提交于 2021-02-18 21:58:22
问题 Is there a way to display the weekday of a datetime object in a template as the actual name of the weekday? Basically I want it to print Friday instead of 5 . 回答1: See the documentation for the built-in date filter. From there you'll see you need to use: l Day of the week, textual, long. 'Friday' 回答2: For clarity's sake, the template tag format character "l" (lower-case "L") can be used in the Django template like so: {{ object.some_date_field | date:"l" }} Django 1.8.2 回答3: You can also use:

How can I validate a post request from an raw HTML form (No django form used)

ぃ、小莉子 提交于 2021-02-18 19:43:55
问题 def update(request, property_id): obj = get_object_or_404(PropertyModel, property_id= form = PropertyModelForm(request.POST or None, instance= if form.is_valid(): form.save() template = 'form.html' context = { 'form': form } return render(request, template, context) have done using Django model from but want to do it using HTML form 回答1: I'd recommend you to use Django forms but if that's not an option you can go ahead and use Javascript and manually checking on the views, here's an extremely

How can I validate a post request from an raw HTML form (No django form used)

雨燕双飞 提交于 2021-02-18 19:43:14
问题 def update(request, property_id): obj = get_object_or_404(PropertyModel, property_id= form = PropertyModelForm(request.POST or None, instance= if form.is_valid(): form.save() template = 'form.html' context = { 'form': form } return render(request, template, context) have done using Django model from but want to do it using HTML form 回答1: I'd recommend you to use Django forms but if that's not an option you can go ahead and use Javascript and manually checking on the views, here's an extremely

How can I validate a post request from an raw HTML form (No django form used)

喜你入骨 提交于 2021-02-18 19:42:10
问题 def update(request, property_id): obj = get_object_or_404(PropertyModel, property_id= form = PropertyModelForm(request.POST or None, instance= if form.is_valid(): form.save() template = 'form.html' context = { 'form': form } return render(request, template, context) have done using Django model from but want to do it using HTML form 回答1: I'd recommend you to use Django forms but if that's not an option you can go ahead and use Javascript and manually checking on the views, here's an extremely

Create object only if other object is successfully created

回眸只為那壹抹淺笑 提交于 2021-02-18 19:09:57
问题 I am fairly new to Django and unfamiliar with the best practices for this situation (in any framework/language, not just python/django). The situation is that when a user first registers on my site, I want to create an "organization" for them if it doesn't exists, and then subsequently create a user for them, which references the organization. I never want to insert one without the other, but I need to create the organization first so that the organization UUID can be saved for each user.

Create object only if other object is successfully created

痞子三分冷 提交于 2021-02-18 19:04:02
问题 I am fairly new to Django and unfamiliar with the best practices for this situation (in any framework/language, not just python/django). The situation is that when a user first registers on my site, I want to create an "organization" for them if it doesn't exists, and then subsequently create a user for them, which references the organization. I never want to insert one without the other, but I need to create the organization first so that the organization UUID can be saved for each user.

Raise validation error in inline field Django

不羁的心 提交于 2021-02-18 18:54:38
问题 I have a model that contains a TabularInline , and I want to raise a validation error when a condition is not valid. My parent model: @admin.register(Even) class EventAdmin(admin.ModelAdmin): list_display = ['id', 'title'] list_display_links = ['id', 'title] inlines = [EventSpecialPriceInline] And my TabularInline: class EventSpecialPriceInline(admin.TabularInline): model = EventSpecialPrice extra = 0 can_delete = True The error I want to raise is when a price of a row is negative