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!');
<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
Post a Comment