简体   繁体   English

Django-Autocomplete-light窗口小部件未显示

[英]Django-Autocomplete-light widgets not showing up

I've just installed Django-Autocomplete-Light and followed the guide on their site . 我刚刚安装了Django-Autocomplete-Light,并按照其网站上的指南进行操作。 I've setup the autocomplete-view and it works as intended (returning a JASON of autocomplete options). 我已经设置了自动完成视图,它按预期工作(返回自动完成选项的JASON)。 I can't seem to get the widgets to show up, though. 不过,我似乎无法显示这些小部件。 in and out of the admin panel. 进入和退出管理面板。

Everything compiles without errors but instead the widget I get an empty drop down selection box. 一切都编译没有错误,但是小部件我得到一个空的下拉选择框。

Image of empty selection box in admin panel 管理面板中空白选择框的图像

This is my settings.py: 这是我的settings.py:

INSTALLED_APPS = [
    'dal',
    'dal_select2',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'selectable',
    'videos.apps.VideosConfig',
]

This is views.py: 这是views.py:

class ActorAutocomplete(autocomplete.Select2QuerySetView):
    def get_queryset(self):
        # Don't forget to filter out results depending on the visitor !

        qs = Actor.objects.all()

        if self.q:
            qs = qs.filter(name__istartswith=self.q)

        return qs

urls.py: urls.py:

url(r'^actor-autocomplete/$', views.ActorAutocomplete.as_view(), name='actor-autocomplete'),

forms.py: forms.py:

class ActorForm(forms.ModelForm):
    class Meta:
        model = Actor
        fields = ('name',)
        widgets = {
            'name': autocomplete.Select(url='videos/actor-autocomplete')
        }

It feels like I'm missing something simple, but I don't know what it is. 感觉好像我缺少一些简单的东西,但是我不知道它是什么。 Perhaps it can't access the static files, but adding 'dal' to installed_app in settings.py should have solved that according to the documentation. 也许它不能访问静态文件,但是根据文档,在settings.py中的install_app中添加“ dal”应该已经解决了。 I'll appreciate any help! 我将不胜感激!

I forgot to mention that Actor.name is of type CharField. 我忘了提到Actor.name是CharField类型。 Perhaps I'm not using the correct widget, but I haven't found one that is specific for CharField. 也许我没有使用正确的小部件,但没有找到特定于CharField的小部件。

As I have the same problem, here is the content of my console in Firefox: 由于我有同样的问题,因此这是Firefox中控制台的内容:

Select2: An instance of jQuery or a jQuery-compatible library was not found. Make sure that you are including jQuery before Select2 on your web page.

It seems that jQuery is needed but not found, but I can't find a way to link it properly. 似乎需要jQuery,但找不到jQuery,但是我找不到正确链接它的方法。

It is also running perfectly in Chromium. 它还在Chromium中完美运行。 I don't have any other browser to test. 我没有其他浏览器要测试。

After some testing, I found out that this was working perfectly on Firefox and Chrome incognito mode. 经过一些测试,我发现它可以在Firefox和Chrome隐身模式下完美运行。 I've disabled all chrome extensions and now it works on my regular chrome as well. 我已经禁用了所有chrome扩展程序,现在它也可以在我的常规chrome上运行。

The problem most likely was one of the extensions but I didn't manage to narrow it down to a specific extension. 问题很可能是扩展之一,但我没有设法将其范围缩小到特定扩展。

TL;DR Changing the browser or opening the site from another chrome user fixes the problem for me. TL; DR更改浏览器或从其他Chrome用户打开网站对我来说解决了这个问题。

I did have the exact same problem. 我确实有完全相同的问题。 It is a problem due to the google chrome cache... It did take me a certain time to identify the cause... to solve it do ctrl + SHIFT + R 这是由于Google Chrome缓存导致的问题...确实花了我一些时间才能确定原因...解决该问题需要按ctrl + SHIFT + R

See this issue on DAL: github Issue 858 在DAL上查看此问题: github Issue 858

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM