working with static file adding in django

static files

url.py(django-1.5)
====

from django.conf.urls import patterns, include, url
from login.views import hello_page, home
from django.contrib import admin
from uploader.views import upload
admin.autodiscover()
import uploader.views
import contacts.views
from django.conf import settings
from django.conf.urls.static import static


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

    url(r'^admin/', include(admin.site.urls)),
    url(r'^upload/', 'uploader.views.upload', name='imageupload'),
    url(r'^$', hello_page, name='home'),
    url(r'^home/', home),
    url(r'^view/',contacts.views.ListContactView.as_view(),name='contacts-list',),
    url(r'^new$', contacts.views.CreateContactView.as_view(), name='contacts-new',),
    url(r'^edit/(?P<pk>\d+)/$', contacts.views.UpdateContactView.as_view(), name='contacts-edit',),


)+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

                                  


(or)



 url.py(django1.8)

from django.conf.urls import include, url
from django.contrib import admin
from login.views import home
from django.conf import settings
from django.conf.urls.static import static
#from . import views

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),

    url(r'^$', 'login.views.home', name='home'),

]

 


  settings.py
====




STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR + '/static'
#STATICFILES_DIRS = (
#    BASE_DIR + '/admin/img/',
#)



#MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
#MEDIA_URL = '/media/'


 


in terminal
======

erp@erp-OptiPlex-330:~/ecommerce$ python manage.py collectstatic

You have requested to collect static files at the destination
location as specified in your settings:

    /home/erp/ecommerce/static

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/inline-delete-8bit.png'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/nav-bg.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/icon_success.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/icon_addlink.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/changelist-bg.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/tooltag-add.png'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/icon_calendar.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/icon_changelink.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/icon_alert.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/default-bg-reverse.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/icon-yes.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/icon_searchbox.png'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/changelist-bg_rtl.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/selector-search.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/nav-bg-reverse.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/nav-bg-grabber.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/tooltag-arrowright.png'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/inline-restore.png'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/icon_clock.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/deleted-overlay.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/default-bg.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/sorting-icons.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/inline-splitter-bg.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/nav-bg-selected.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/selector-icons.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/icon_deletelink.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/inline-restore-8bit.png'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/icon-unknown.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/icon_error.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/inline-delete.png'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/icon-no.gif'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/gis/move_vertex_off.png'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/img/gis/move_vertex_on.png'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/jquery.min.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/related-widget-wrapper.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/inlines.min.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/prepopulate.min.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/collapse.min.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/inlines.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/urlify.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/SelectBox.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/core.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/jquery.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/collapse.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/prepopulate.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/timeparse.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/actions.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/calendar.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/jquery.init.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/actions.min.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/LICENSE-JQUERY.txt'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/SelectFilter2.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/css/widgets.css'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/css/login.css'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/css/dashboard.css'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/css/forms.css'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/css/rtl.css'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/css/ie.css'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/css/base.css'
Copying '/usr/local/lib/python2.7/dist-packages/Django-1.8.3-py2.7.egg/django/contrib/admin/static/admin/css/changelists.css'

62 static files copied to '/home/erp/ecommerce/static'.
erp@erp-OptiPlex-330:~/ecommerce$
 




login.html
======



<html>
<body>
<h1>
Links
</h1>


{% load staticfiles %}
<img src="/static/icon_addlink.gif" width="10%" height="130">


</body>

</html>
 





settings.py(change these file
====




STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR + '/static'
STATICFILES_DIRS = (
    BASE_DIR + /static'/admin/img/',
)



#MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
#MEDIA_URL = '/media/'






output
=====


Links

 

No comments:

Post a Comment