django-templates

django smart selects on Django version 3.0.1 - error ImportError: cannot import name 'six' from 'django.utils'

ぃ、小莉子 提交于 2020-01-15 01:48:07
问题 Installed django-smart-selects (pip install django-smart-selects) and is not working on django version 3.0.1 I configured using the official installation guide. enter code here $ python manage.py runserver Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self.

Edit Django User admin template

[亡魂溺海] 提交于 2020-01-14 18:45:09
问题 I need to edit the template shown for editing a specific user. I need to display some additional data that doesn't fit in with an include-style. I apologise for the short question... but that's pretty much all there is at the moment. 回答1: If you can't accomplish what you want with just subclassing admin.ModelAdmin , you can create a directory "admin/auth" in your template directory and put a "change_form.html" in there. In this template you can override blocks that are available e.g. {% block

Django iterate over ClearableFileInput widget field

拟墨画扇 提交于 2020-01-14 14:44:16
问题 currently have a model that has a model.FileField() attribute, and when rendering in my django template I just iterate over the fields, such as {% for field in form.visible_fields %} <div class="form-group"> {{field.errors}} <label for="{{field.auto_id}}">{{field.label}}</label> {{field}} {% endfor %} However, when the template renders the ClearableFileInput widget, I want to add some space between the href and the checkbox for clearing the widget. Any ideas on how to access those specific

Auto Generated Slugs in Django Admin

血红的双手。 提交于 2020-01-14 05:57:09
问题 I have an app that will one day allow front-end crud, which will create the slug with slugify . Right now though, all the object creation is being done in the admin area and I was wondering if there is a way to auto generate slugs while creating and saving an object from within admin? Here is the method for slugify for the front-end; not sure if its even relevant. Thank you. def create_slug(instance, new_slug=None): slug = slugify(instance.title) if new_slug is not None: slug = new_slug qs =

django render_to_response

橙三吉。 提交于 2020-01-14 03:05:15
问题 I'm putting ...}, context_instance=RequestContext(request)) at the end of all my render_to_response 's. I'm sure this is not right. Can anyone tell me when I should be using these? 回答1: You are doing it "right". This means that all of the Context Processors will run on this view, and you will have access to all of the juicy bits in your template. The other way to do this is to use direct_to_template , which saves you having to instantiate a RequestContext object, but has the same outcomes.

How to make STATIC_URL work in external JS Files (Django)

自古美人都是妖i 提交于 2020-01-13 19:28:32
问题 I am trying to use STATIC_URL in external javascript file. I was expecting the result as it is working in template, but I found that it is not working in external Javascript file. Please also tell me some work around to make STATIC_URL work in javascript file as it will make my project more manageable. Also I am sending many ajax request and i want to have something like url template tag in my JS file. Please let me know if you know solution of any of them. Thanks 回答1: I use a simple Django

Django won't serve static files while using development server

巧了我就是萌 提交于 2020-01-13 12:17:30
问题 I just started a new development server for a website I am working on and I can't seem to get the Django development server to serve the static files I have for CSS and other things. The CSS for the admin site loads fine. I am running it in a virtualenv sandbox. In settings.py I've messed around with MEDIA_ROOT and MEDIA_URL. So far for MEDIA_ROOT I've tried. MEDIA_ROOT = '/home/wluw/wluw/wluw/media' and MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'media') I changed my ADMIN_MEDIA

Django urldecode in template file

守給你的承諾、 提交于 2020-01-13 09:33:05
问题 is there any way do the urldecode in Django template file? Just opposite to urlencode or escape I want to convert app%20llc to app llc 回答1: You could create a simple custom filter around urllib.unquote For instance: from django.template.defaultfilters import stringfilter from urllib import unquote @stringfilter def unquote_raw(value): return unquote(value) and now you can have this in your django template file: {{ raw|unquote_raw }} 回答2: you have to write something like this instead of the

List directory file contents in a Django template

大憨熊 提交于 2020-01-13 09:27:36
问题 I'm just learning Python & Django. (Thanks to everyone who contributes here -- it's been an invaluable resource!) One seemingly basic thing that I'm having trouble with is rendering a simple list of static files (say the contents of a single repository directory on my server) as a list of downloadable links. Whether this is secure or not is another question, but suppose I want to do it... This post helped steer me in the right direction: Python directory list returned to Django template This

Django admin site: How does the Add User page work (more fields on edit)?

南笙酒味 提交于 2020-01-13 07:00:28
问题 I was wondering how they made it possible to display more fields in the User page of the Django admin site. If you create a new User you only have some basic fields to fill in, but if you reopen that user (edit mode) then you see a lot more fields to fill in. I'm trying to achieve the same, I had a look at the add_form.html template but I can't really get my head around it. I guess I'm looking for a way of specifying different fields = [] sets based on the edit status of the document. Thanks!