django

Customize ClearableFileInput in django template

天涯浪子 提交于 2021-02-19 05:10:03
问题 I've got a form with profile_picture=ImageField field set to the initial value. It's using ClearableFileInput widget. I need to customize the form in the template, so I can't simply use {{ form.profile_picture}} . How can I split field elements and obtain something which looks like this: {{ with picture=form.profile_picture }} {{ picture.label_tag }} <a href="{{ picture.url }}"> <img src="{{ picture.url }}"> </a> {{ picture.clear-picture }} where {{ picture.clear-picture }} should generate

render two views to a single html template

风格不统一 提交于 2021-02-19 04:54:51
问题 I have two views and I want to render those views to a single HTML page. I know how to render a single view to an HTML page but don't know how to render two views to a single HTML page. views.py file from django.shortcuts import render from django.http import HttpResponse from app.models import * # Create your views here. def collegeview(request): if request.method == 'POST': form = collegeform(requst.POST) if form.is_valid(): form.save() return HttpResponse('its done here') else: form =

`basename` argument not specified, and could ' \

£可爱£侵袭症+ 提交于 2021-02-19 04:53:10
问题 I am getting the below error again and again.I am trying to solve it from morning but nothing is happening. assert queryset is not None, ' basename argument not specified, and could ' \ AssertionError: basename argument not specified, and could not automatically determine the name from the viewset, as it does not have a .queryset attribute. models.py class Language(models.Model): A = models.CharField(max_length=50) B = models.ForeignKey(User,on_delete=models.CASCADE,null=True) C = models

django on IIS, process exited unexpectedly

℡╲_俬逩灬. 提交于 2021-02-19 04:36:12
问题 I have read every article I could find on this topic but I'm still unable to run django project on IIS. The error message is 500 Internal Server Error, c:\program files (x86)\python 3.5\python.exe - The FastCGI process exited unexpectedly. Tracing rule for error 500 provides the following: Error -FASTCGI_UNEXPECTED_EXIT Warning -SET_RESPONSE_ERROR_DESCRIPTION ErrorDescription c:\program files (x86)\python 3.5\python.exe - The FastCGI process exited unexpectedly Warning -MODULE_SET_RESPONSE

how to display inline elements in list_display?

我怕爱的太早我们不能终老 提交于 2021-02-19 04:13:30
问题 I have the following problem: I have two models: Article and Comment, in Comments, i have parent = models.ForeignKey(Article). I have it set up so that Comments is inline to ArticleAdmin(admin.ModelAdmin), and CommentInline(admin.StackedInline). What i would like is that for Article list view (elements chosen in list_display), I would like to display snippets of latest comments so that the user does not have to click into each individual comments to see the changes. Now i know that i can

Django: Object of type 'datetime' is not JSON serializable

柔情痞子 提交于 2021-02-19 03:38:29
问题 I'm trying to save a date in my sessions. I always receive the error Object of type 'datetime' is not JSON serializable . I found this here in the Django documentation: stored as seconds since epoch since datetimes are not serializable in JSON. How can I save my expiry_date as seconds instead of datetime? code = social_ticketing_form.cleaned_data['a'] expiry_date = timezone.now() + timezone.timedelta(days=settings.SOCIAL_TICKETING_ATTRIBUTION_WINDOW) request.session[social_ticketing_cookie

Django: Object of type 'datetime' is not JSON serializable

五迷三道 提交于 2021-02-19 03:38:26
问题 I'm trying to save a date in my sessions. I always receive the error Object of type 'datetime' is not JSON serializable . I found this here in the Django documentation: stored as seconds since epoch since datetimes are not serializable in JSON. How can I save my expiry_date as seconds instead of datetime? code = social_ticketing_form.cleaned_data['a'] expiry_date = timezone.now() + timezone.timedelta(days=settings.SOCIAL_TICKETING_ATTRIBUTION_WINDOW) request.session[social_ticketing_cookie

Django: Run a script right after runserver

萝らか妹 提交于 2021-02-19 03:37:08
问题 Context: I have a table on the database that uses values from an external database. This external database updates its values periodically. Problem: In order to update my database everytime i start the server, I want to run a script right after the runserver. Potential Solution: I have seen that it is possible to run a script from a certain app, which is something I'm interested in. This is achievable by using the django-extensions : https://django-extensions.readthedocs.io/en/latest

Django Whitenoise 500 server error in non debug mode

倾然丶 夕夏残阳落幕 提交于 2021-02-19 03:28:10
问题 I am using django in my local machine. In order to serve the static files I used WhiteNoise along with it. When DEBUG = True all static files are correctly served. But when I changed DEBUG = False and set ALLOWED_HOSTS = ['*'] I'm getting 500 server error. However admin site loads without any error. Also when I comment out STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' I don't get 500 error. I followed the documentation given in http://whitenoise.evans.io/en

Django global queryset

邮差的信 提交于 2021-02-19 03:08:58
问题 I would like to have a global variable in my django app that stores resulting list of objects that I later use in some functions and I don't want to evaluate queryset more that once, i do it like this: from app.models import StopWord a = list(StopWord.objects.values_list('word', flat=True)) ... def some_func(): ... (using a variable) ... This seems ok to me but the problem is that syncdb and test command throw an exception: django.db.utils.DatabaseError: (1146, "Table 'app_stopword' doesn't