Setting up jQuery in debian with virtualenv

115 views
Skip to first unread message

Gary Roach

unread,
Nov 9, 2016, 3:27:30 PM11/9/16
to Django users
Hi all,

I am just starting to use jQuery and Ajax in my project and am having
trouble setting things up.

I am using Eclipse + pyDev as an IDE. This setup stores everything in a
workspace directory in my home directory. Instead of putting the whole
project inside a virtualenv wrapper, things work better if the venv is
external to the actual project files and the venv contents referenced in
the Eclipse setup. In that venv file (djenv) there is the following:

> /home/gary/workspace/djenv/lib/python3.5/site-packages/django/contrib/admin/static/admin/js/vendor/jquery/jquery.min.js


Now to the setup of my main html page. According to W3schools.com I
should include one of the following in the html head section:

> <head>
> <script src="jquery-3.1.1.min.js"></script>
> </head>

or

> <head>
> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
> </head>

Neither of these fit my situation. I don't have a separate
jquery-3.1.1.min.js file and don't want to use the google source.

What I wish to know is can I use something like:
> <head>
> <script src=
"djenv/lib/python3.5/site-packages/django/contrib/admin/static/admin/js/vendor/jquery/jquery.min.js"</script>
></head>

or can I use just <script src="jquery.min.js" since the file is already
referenced in my django setup.

Any help will be sincerely appreciated.

Gary R.

ludovic coues

unread,
Nov 9, 2016, 4:42:58 PM11/9/16
to django...@googlegroups.com
Hello,

Django provide tools to deals with static files like javascript or
css. The documentation is at [1].

[1] https://docs.djangoproject.com/en/1.10/howto/static-files/
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1b51ba33-73a7-63f1-1de2-a3ada145fbc5%40verizon.net.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

Gary Roach

unread,
Nov 9, 2016, 4:55:22 PM11/9/16
to django...@googlegroups.com
Ludovic

Thank you for the reply but I know how to use static files. The problem
is that I already have a jquery file under version control inside my
virtual environment wrapper and do not wish to use an external file .
Use of a normal static file will open my application up to uncontrolled
version shifts. I want to know how to use the pip installed version of
the jquery file if possible.

Gary R.

Javier Guerra Giraldez

unread,
Nov 9, 2016, 5:12:56 PM11/9/16
to django...@googlegroups.com
On 9 November 2016 at 13:54, Gary Roach <gary71...@verizon.net> wrote:
> I want to know how to use the pip installed version of the jquery file if
> possible.


you can check what the admin templates do. probably something like
{% url "admin/js/vendor/jquery/jquery.min.js" %}

--
Javier

Antonis Christofides

unread,
Nov 10, 2016, 2:57:51 AM11/10/16
to django...@googlegroups.com
Hi,

If, as you say, you "have a jquery file under version control inside [your]
virtual environment wrapper", I believe you are doing something wrong. We
normally don't put jquery files in virtualenv (although `pip install django`
will do so), and we normally do not version control the virtualenv.

If virtualenv is not clear to you, I'd propose to take a look at
http://djangodeployment.com/2016/11/01/virtualenv-demystified/ and then re-ask
your question.

Regards,

Antonis Christofides
http://djangodeployment.com

Michal Petrucha

unread,
Nov 10, 2016, 3:38:00 AM11/10/16
to django...@googlegroups.com
On Wed, Nov 09, 2016 at 01:54:57PM -0800, Gary Roach wrote:
> Ludovic
>
> Thank you for the reply but I know how to use static files. The problem is
> that I already have a jquery file under version control inside my virtual
> environment wrapper and do not wish to use an external file . Use of a
> normal static file will open my application up to uncontrolled version
> shifts. I want to know how to use the pip installed version of the jquery
> file if possible.
>
> Gary R.

Could you please elaborate on that a little bit? Virtualenvs are
normally used to install Python packages, which jquery is not. Jquery
really *is* a static asset, it's just a file that the browser
downloads from your server as it is, without any server-side
processing. That's the definition of a static asset.

How do you install jquery? Are you using some kind of python-package
wrapper that contains the jquery static file? What package exactly is
it?

Chances are that if you use some kind of django-jquery package, all
you need to do is add that package to your ``INSTALLED_APPS``, and as
long as your ``STATICFILES_FINDERS`` setting includes
``django.contrib.staticfiles.finders.AppDirectoriesFinder``, it might
“just work” (as in, you'd reference it using
``{% static "js/jquery.js" %}`` or something).

However, that's just a guess, because it's not very clear to me from
your description what kind of setup you have there. Anyway, as far as
Django is concerned, it really does not care where the static file is
coming from, as long as you configure your static file finders to see
the file.

Cheers,

Michal
signature.asc

Gary Roach

unread,
Nov 10, 2016, 12:54:20 PM11/10/16
to django...@googlegroups.com
Hi,

Sorry about the confusion. I misspoke. I was trying to imply that there
was a jquery.min.js file in the venv (djenv) file. As you implied, it
was installed with pip django. A very bad choice of words.

I am trying to set up my project so that I am not using a system version
of jquery since the system version is subject to change every time I
update my debian system (whiich I do about once a week). I suppose what
I really want to know is how do I get a "sequestered" version of
jquery.min.js installed. I have tried to use a pointer to the copy in
the djenv directory (Eclipse allows this). After doing this there is a
file jquery.min.sj shows up in my static file directory. Unfortunately,
when I do a runserver I still get a - "GET /static/jquery.min.js
HTTP/1.1" 404 1652 - error. What's next?

Gary R.

Luis Zárate

unread,
Nov 10, 2016, 1:23:18 PM11/10/16
to django...@googlegroups.com
Mmm why not just download Jquery and create a folder called static inside one controlled app, maybe pone inside the project.

If you want, you can use django admin jquery but $ is not available because django use django.JQuery for prevent conflict with custom user jquery
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c3697c2d-1980-9d06-3f7c-111e43440d00%40verizon.net.

> For more options, visit https://groups.google.com/d/optout.
>

--
"La utopía sirve para caminar" Fernando Birri



ludovic coues

unread,
Nov 10, 2016, 2:43:06 PM11/10/16
to django...@googlegroups.com
 {% static 'admin/js/vendor/jquery/jquery.min.js' %}

Assuming you have django.contrib.admin in your INSTALLED_APP, this will do what you want.


>>>>> To post to this group, send email to django...@googlegroups.com.
>>>>> Visit this group at https://groups.google.com/group/django-users.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/django-users/1b51ba33-73a7-63f1-1de2-a3ada145fbc5%40verizon.net.
>>>>>
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c3697c2d-1980-9d06-3f7c-111e43440d00%40verizon.net.
> For more options, visit https://groups.google.com/d/optout.
>

--
"La utopía sirve para caminar" Fernando Birri


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--

Gary Roach

unread,
Nov 12, 2016, 3:24:46 PM11/12/16
to django...@googlegroups.com
Thanks all,

I installed libjs-jquery into my active venv directory. It turns out that libjs-jquery actually has 3 different virsions in it . I copied the jquery.js  file over to my /static/ file in Eclipse. It works fine.

Gary R.
Reply all
Reply to author
Forward
0 new messages