Re: Query regarding Jija templates with django project
Hey Red, Thank you for your reply. Your suggestion did the trick. Now I am facing issues with static files, especially for CSS files. There were issues for images files, but I got that rectified. I know that the location that I have mentioned in the HTML pages has the CSS files. Still I am getting the below error: Not Found: /blog/contact/%{ static 'CSS/tooplate_style.css' %} Not Found: /blog/contact/%{ static 'CSS/ddsmoothmenu.css' %} [30/Oct/2019 10:41:07] "GET /blog/contact/%%7B%20static%20'CSS/tooplate_style.css'%20%%7D HTTP/1.1" 404 3124 [30/Oct/2019 10:41:07] "GET /blog/contact/%%7B%20static%20'CSS/ddsmoothmenu.css'%20%%7D HTTP/1.1" 404 3118 Not Found: /blog/contact/%{ static 'CSS/ddsmoothmenu.css' %} [30/Oct/2019 10:41:07] "GET /blog/contact/%%7B%20static%20'CSS/ddsmoothmenu.css'%20%%7D HTTP/1.1" 404 3118 Below is the snippet of my static file settings: STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), )Below is my static dir structure as seen in my pycharm. I went through below stackoverflow web link, but the suggestion don't seem to be working for me. Django - Static file not found | | | | | | | | | | | Django - Static file not found I've seen several posts for this issue but didn't found my solution. I'm trying to serve static files within my... | | | It would great if you could suggest . Regards, Amitesh On Saturday, 26 October, 2019, 4:42:05 AM IST, red wrote: Hello, Your views have a 'name' attribute. You can also give a name to an app in the urls.py file of the app, right above your urlpatterns list: app_name = "myappname" urlpatterns = [ path('', views.index, name='index'), path('about', views.about, name='about'), path('blog', views.blog, name='blog'), ] Then, when you need to put a link to a another page in your template, use the following syntax: Home About Us Regards, Red On 25/10/2019 21:01, 'Amitesh Sahay' via Django users wrote: Hello Team, I am kind of new to software development, and trying to find my feat. I have a queries which could be quite dumb to most of you, but I need to know. As far as I know, we need Jija templates in the HTML files, so that we can assign correct path of the static files. Its a general practice to create base.html and extend this in other HTML files. Since, I am new to development, so I want to do things in a stupid way, I have a HTML templates, and I do not wish to create base.html for now. Therefore, if I want to render the html page, I need to create views.py , urls.py, and modify the HTML pages to use 'static' any where required. Below are the snippet of my test environment. views.py from django.shortcuts import render, get_object_or_404 def index(request): return render(request, 'index.html') def blog(request): return render(request, 'blog.html') def about(request): return render(request, 'about.html') project/urls.py from django.contrib import admin from django.urls import path, include from django.conf import settings from django.conf.urls.static import static urlpatterns = [ path('admin/', admin.site.urls), path('blog/', include('BLOG.urls')) ] if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) APP/urls.py from django.urls import path from django.conf import settings from . import views urlpatterns = [ path('', views.index, name='index'), path('about', views.about, name='about'), path('blog', views.blog, name='blog'), ] below is the HTML(index.html) file, which I modified as per my limited understanding. {% load staticfiles %} {% block content %} http://www.w3.org/1999/xhtml";> Orange Theme - Free Website Template var flashvars = {}; flashvars.xml_file = "photo_list.xml"; var params = {}; params.wmode = "transparent"; var attributes = {}; attributes.id = "slider"; swfobject.embedSWF("flash_slider.swf", "flash_grid_slider", "440", "220", "9.0.0", false, flashvars, params, attributes); /*** * Smooth Navigational Menu- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code ***/ ddsmoothmenu.init({ mainmenuid: "tooplate_menu", //menu DIV id orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v" classname: 'ddsmoothmenu', //class added to menu's outer DIV //customtheme: ["#1c5a80", "#18374a"], contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"] }) Orange HTML Template Home
Re: Query regarding Jija templates with django project
Hello, Your views have a 'name' attribute. You can also give a name to an app in the urls.py file of the app, right above your urlpatterns list: app_name = "myappname" urlpatterns = [ path('', views.index, name='index'), path('about', views.about, name='about'), path('blog', views.blog, name='blog'), ] Then, when you need to put a link to a another page in your template, use the following syntax: Home About Us Regards, Red On 25/10/2019 21:01, 'Amitesh Sahay' via Django users wrote: > Hello Team, > > I am kind of new to software development, and trying to find my feat. > I have a queries which could be quite dumb to most of you, but I need > to know. > > As far as I know, we need Jija templates in the HTML files, so that we > can assign correct path of the static files. > > Its a general practice to create base.html and extend this in other > HTML files. Since, I am new to development, so I want to do things in > a stupid way, I have a HTML templates, and I do not wish to create > base.html for now. Therefore, if I want to render the html page, I > need to create views.py , urls.py, and modify the HTML pages to use > 'static' any where required. Below are the snippet of my test environment. > > views.py > > from django.shortcuts import render, get_object_or_404 > > > def index(request): > return render(request, 'index.html') > > > def blog(request): > return render(request, 'blog.html') > > > def about(request): > return render(request, 'about.html') > project/urls.py > > from django.contrib import admin > from django.urls import path, include > from django.conf import settings > from django.conf.urls.static import static > > urlpatterns = [ > path('admin/', admin.site.urls), path('blog/', include('BLOG.urls')) > ] > > if settings.DEBUG: >urlpatterns += static(settings.STATIC_URL, > document_root=settings.STATIC_ROOT) > APP/urls.py > > from django.urls import path > from django.conf import settings > from . import views > > urlpatterns = [ > path('', views.index, name='index'), path('about', views.about, > name='about'), path('blog', views.blog, name='blog'), ] > below is the HTML(index.html) file, which I modified as per my limited > understanding. > > {% load staticfiles %} > {% block content %} > xmlns="http://www.w3.org/1999/xhtml";> http-equiv="Content-Type" content="text/html; charset=utf-8" /> Orange > Theme - Free Website Template > content="" /> > var flashvars = {}; >flashvars.xml_file = "photo_list.xml"; >var params = {}; >params.wmode = "transparent"; >var attributes = {}; >attributes.id = "slider"; >swfobject.embedSWF("flash_slider.swf", "flash_grid_slider", "440", "220", > "9.0.0", false, flashvars, params, attributes); > src="{% static 'js/ddsmoothmenu.js' %}"> > /*** > * Smooth Navigational Menu- (c) Dynamic Drive DHTML code library > (www.dynamicdrive.com) > * This notice MUST stay intact for legal use > * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code > ***/ > > ddsmoothmenu.init({ >mainmenuid: "tooplate_menu", //menu DIV id >orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v" >classname: 'ddsmoothmenu', //class added to menu's outer DIV >//customtheme: ["#1c5a80", "#18374a"], >contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"] > }) > > id="tooplate_header"> Orange HTML > Template > Home href="{% 'about.html' %}">About Us History > Our Team Vision and Mission > Portfolio href="#">Website Templates Web Design > Free Templates HTML CSS > Layouts Web Developmenthref="{% 'blog.html' %}">Blog Contact id="tooplate_social">href="#"> href="#"> /> id="flash_grid_slider"> href="http://www.adobe.com/go/getflashplayer";> src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"; > alt="Get Adobe Flash player" /> > Website Template >Aliquam in odio ut ipsum mollis facilisis. Integer est > sem, dignissim quis auctor vel, dapibus vel massa. Curabitur vulputate ligula > vel mi semper tempus. > class="cleaner">id="tooplate_main_top"> class="col_fw"> New > Standard > Vivamus a velit. Vivamus leo velit, convallis id, ultrices sit amet, > validate http://validator.w3.org/check?uri=referer"; > rel="nofollow">XHTML and href="http://jigsaw.w3.org/css-validator/check/referer"; > rel="nofollow">CSS. href="#">Detail High > Quality /> Donec pharetra orci id tortor cursus eu ultricies velit vehicula. > Phasellus eu ante tellus. Detail class="col_allw270 fp_service_box col_last"> Solid Platform src="{% static 'img/rosette-48px.png' %}" alt="Rosette" /> Curabitur sed > lectus id erat viverra consectetur nec in sapien. Etiam vitae tortor mi. > Detail > class="cleaner"> > Pages class="botto
Query regarding Jija templates with django project
Hello Team, I am kind of new to software development, and trying to find my feat. I have a queries which could be quite dumb to most of you, but I need to know. As far as I know, we need Jija templates in the HTML files, so that we can assign correct path of the static files. Its a general practice to create base.html and extend this in other HTML files. Since, I am new to development, so I want to do things in a stupid way, I have a HTML templates, and I do not wish to create base.html for now. Therefore, if I want to render the html page, I need to create views.py , urls.py, and modify the HTML pages to use 'static' any where required. Below are the snippet of my test environment. views.py from django.shortcuts import render, get_object_or_404 def index(request): return render(request, 'index.html') def blog(request): return render(request, 'blog.html') def about(request): return render(request, 'about.html') project/urls.py from django.contrib import admin from django.urls import path, include from django.conf import settings from django.conf.urls.static import static urlpatterns = [ path('admin/', admin.site.urls), path('blog/', include('BLOG.urls')) ] if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)APP/urls.py from django.urls import path from django.conf import settings from . import views urlpatterns = [ path('', views.index, name='index'), path('about', views.about, name='about'), path('blog', views.blog, name='blog'), ]below is the HTML(index.html) file, which I modified as per my limited understanding. {% load staticfiles %} {% block content %} http://www.w3.org/1999/xhtml";> Orange Theme - Free Website Template var flashvars = {}; flashvars.xml_file = "photo_list.xml"; var params = {}; params.wmode = "transparent"; var attributes = {}; attributes.id = "slider"; swfobject.embedSWF("flash_slider.swf", "flash_grid_slider", "440", "220", "9.0.0", false, flashvars, params, attributes); /*** * Smooth Navigational Menu- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code ***/ ddsmoothmenu.init({ mainmenuid: "tooplate_menu", //menu DIV id orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v" classname: 'ddsmoothmenu', //class added to menu's outer DIV //customtheme: ["#1c5a80", "#18374a"], contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"] }) Orange HTML Template Home About Us History Our Team Vision and Mission Portfolio Website Templates Web Design Free Templates HTML CSS Layouts Web Development Blog Contact http://www.adobe.com/go/getflashplayer";> http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"; alt="Get Adobe Flash player" /> Website Template Aliquam in odio ut ipsum mollis facilisis. Integer est sem, dignissim quis auctor vel, dapibus vel massa. Curabitur vulputate ligula vel mi semper tempus. New Standard Vivamus a velit. Vivamus leo velit, convallis id, ultrices sit amet, validate http://validator.w3.org/check?uri=referer"; rel="nofollow">XHTML and http://jigsaw.w3.org/css-validator/check/referer"; rel="nofollow">CSS. Detail High Quality Donec pharetra orci id tortor cursus eu ultricies velit vehicula. Phasellus eu ante tellus. Detail Solid Platform Curabitur sed lectus id erat viverra consectetur nec in sapien. Etiam vitae tortor mi. Detail Pages Home About Us