A simple example of Django and CSS

前端 未结 5 2023

I\'m new to Django, and am trying to set up a really simple Django app.

Now, I\'m up to chapter 5 in the Django online book : http://www.djangobook.com/en/2.0/chapte

5条回答
  •  一向
    一向 (楼主)
    2020-12-08 03:02

    finally i got after many days here is how should be done 1> you need your static file in your app along with in your project 2> here is setting.py

       if DEBUG:
       STATIC_ROOT = "/PycharmProjects/don/admin/shopping/static/css"
    
        STATICFILES_DIRS =(
         #os.path.join(os.path.dirname(BASE_DIR),"static","static"),
         os.path.join(BASE_DIR, "static"),
        )
    

    3>views.py

            from django.views.generic import TemplateView
            class HomeView(TemplateView):
                   template_name = 'index.html'
    

    4> template file

           {% load staticfiles %}
            
    

    5> urls.py

                from shopping.views import HomeView 
                 from django.conf import settings
                 from django.conf.urls.static import static
               urlpatterns = [
                url(r'^admin/', admin.site.urls),
                 url(r'^$', HomeView.as_view())
              ]
            if settings.DEBUG:
           urlpatterns+=static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
    
    6>     python manage.py collectstatic  
    
    have fun :)
    

提交回复
热议问题