question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Static files not loading for autocomplete in non-admin

See original GitHub issue

Template code:

{% load static %}
<DOCTYPE HTML>
<html>
	<head>
		<title>Create a Course</title>
		</head>
	<body>
	 	<h1> Register a new course here</h1>
	 	{% if course_registered %}
	 	Rango says: <strong>Thanks</strong>
	 	<a href="/faculty">Return to homepage</a> <br />
	 	{% else %}
	 	<strong>register here</strong>
		 	<form id="course_form" method="post" action="/faculty/create_course/"
		 		enctype="multipart/form-data">
		 		{% csrf_token %}
		 		{{ course_form.as_p }}
		 		<h2>Select Students:</h2>
		 		{{ year_form }}
		 		{{ branch_form }}
		 		<input type="submit" name="submit" value="Register" />
		 	</form>
	 	{% endif %}
	</body>
	<script type="text/javascript" src="{% static 'admin/js/jquery.js' %}"></script>
	<script type="text/javascript" src="{% static 'autocomplete_light/autocomplete.init.js' %}"></script>
	<script type="text/javascript" src="{% static 'autocomplete_light/select2.js' %}"></script>
	{{ form.media }}
</html>

I have run python manage.py collectstatic and collected my static files in static folder under root directory of my project. Also i have set my static folder in settings.py file.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jpiccommented, Jan 8, 2018

Does it work when you remove UserForm.Méta.widgets ? The field should deal with the widget by default shouldn’t it ?

Le 8 janv. 2018 20:37, “Bas Van Gaalen” notifications@github.com a écrit :

Same problem here: the required media files do not load.

I checked out the example project of @jpic https://github.com/jpic, which works indeed perfectly.

But if I change the view to a FormView, the form to a normal forms.Form instead of a ModelForm, and use autocomplete.ListSelect2 instead of autocomplete.ModelSelect2Multiple, then it stops working. The media files, as described in dal_select2.widgets.Select2WidgetMixin, will not be rendered in the html anymore.

In fact, from a python shell:

In [1]: from rbansalrahul6_project.urls import UserForm

In [2]: u = UserForm()

In [3]: u.media Out[3]: <django.forms.widgets.Media at 0x1055298d0>

In [4]: u.media.render() Out[4]: u’’

That’s the result with this form and view in the urls.py:

class UserForm(forms.Form): groups = fields.Select2ListChoiceField()

class Meta:
    widgets = dict(
        groups=autocomplete.ListSelect2('group_autocomplete'),
    )
    exclude = []

class UserUpdate(generic.FormView): template_name = ‘auth/user_form.html’ form_class = UserForm

For now I’m not sure why this happens, as both autocomplete. ModelSelect2Multiple and autocomplete.ListSelect2 inherit from Select2WidgetMixin, which holds the media…

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yourlabs/django-autocomplete-light/issues/805#issuecomment-356072586, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFxrNBsO0ZblkMQVDGztQ3lpouMJppzks5tIm5lgaJpZM4MV6H2 .

1reaction
jpiccommented, Mar 8, 2017

“I am having problem in loading required static files.”

What’s happening on the network ? Does the Network tab of the firefox or webkit inspector report any error ?

I just spent 12 minutes creating a new project from scratch and the static files all load fine and the autocomplete widget i’ve setup works fine: https://github.com/jpic/rbansalrahul6_project

Create some groups and a user and visit localhost:8000/user/1/

Also, here is the diff, from a fresh django-admin started project, to a working DAL example outside the admin: jpic/rbansalrahul6_project@9b98471 if that is of any help, would you like to complete our tutorial chapter about static files ? In addition to Django’s own documentation about static files, this crash course aiming at incepting the concepts behind static files may help: blog.yourlabs.org/post/30382323418/surviving-djangocontribstaticfiles-or-how-to

Otherwise, please either make a simple demo project either make a better report of what you’re experiencing, here are links which are a must-read and that will definitely help you understand what we need in order to be of any help 😃

http://www.chiark.greenend.org.uk/~sgtatham/bugs.html http://stackoverflow.com/help/how-to-ask

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the admin autocomplete field in a custom form?
Instead of adding the static files yourself just add {{form.media}} in html template it will automatically import the required files. – Software ...
Read more >
Django test AJAX autocomplete Documentation - Read the Docs
{% load static %}. {% load staticfiles %}. {% block branding %}. <title>Django autocomplete example</title>. {% endblock %}.
Read more >
Super Page Cache for Cloudflare – Plugin WordPress
This plugin will help you to cache not only the static files (e.g. CSS, JS, images etc.) but also the HTML webpages generated...
Read more >
Quick start — django-autocomplete-light 1.0.26 documentation
staticfiles, then you're on your own to manage staticfiles. This is an example of how you could load the javascript: <script src="http://ajax.googleapis.com/ ...
Read more >
3.8.0 :: Hue SQL Assistant Documentation - Hue Guide
Hue HA; Static files caching; Hive 1.1 support; Major upgrade of Django 1.6 ... 3ab7bc5 [spark] Hide and not load Assist if Beeswax...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found