How to add java script file in django

1 ) Create index.html inside the 

<p>my first HTML page </p>

{% load staticfiles %}

<script src={% static "js/hello.js" %} type="text/javascript"></script>


2 ) Edit views.py with

from django.shortcuts import render
# Create your views here.
def home(request):
    return render(request,'home.html')


3 ) Edit urls.py with

from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'perfumes.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^home/$','perfum.views.home', name='home'),
)


4 ) Edit settings.py with

STATIC_URL = '/static/'

5 ) Create hello.js inside static/js/hello.js

alert('Hello World!');

Comments

Popular posts from this blog

AttributeError: Got AttributeError when attempting to get a value for field `abc` on serializer `PfleSerializer`. The serializer field might be named incorrectly and not match any attribute or key on the `QuerySet` instance. Original exception text was: 'QuerySet' object has no attribute 'abc'.

ImportError: No module named regex