I am stuck with this : < a href="{% url 'newapp:home' %}" > revWaves< /a>
Error message is : "NoReverseMatch"
Reverse for 'home()' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
I have created namespace for 'newapp' and url path is also correct i.e. /static/newapp/home.html and above < a href="{% url 'newapp:home' %}"> revWaves< /a> goes into header.html
So i am not able to figure out what is the error. Kindly help.
Main Urls.py
from django.conf.urls import url , include
from django.contrib import admin
urlpatterns = [
url(r'^newapp/', include('newapp.urls', namespace='newapp')),
]
newapp urls.py
from django.conf.urls import url , include
from . import views
urlpatterns = [
url(r'^$',views.home) ,
url(r'^about$',views.about) ,
url(r'^services',views.service) ,
url(r'^customers',views.customer),
url(r'^contact',views.contact) ,
]
views.py
from django.shortcuts import render
# Create your views here.
def home(request) :
return render(request, 'newapp/home.html')
def about(request):
return render(request, 'newapp/about.html')
def service(request):
return render(request, 'newapp/services.html')
def customer(request):
return render(request, 'newapp/customers.html')
def contact(request):
return render(request, 'newapp/contact.html')
header.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Ady Rules</title>
<meta charset="utf-8"/>
{% load static %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css?family=Satisfy" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="{% static "newapp/style.css" %}"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.js"></script>
<style>
h1.intro {
color: brown;
}
</style>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- logo --!>
<div class="navbar-header">
<a class="navbar-brand" href="{% url 'newapp:home' %}"> revWaves</a>
<div>
</div>
</head>
<body class="body" style="background-color:#f6f6f6">
{% block content %}
{% endblock %}
</body>
</html>
home.html
{% extends "newapp/header.html" %}
{% block content %}
<h2>Hey There ! How Ya Doin ? </h2>
<h2> Welcome to the world of Programming !!</h2>
<h1 class = "intro"> New Appppppppp !!!!!!</h1>
{% endblock %}
Related
I'm making my first Django app and I'm trying to set up my signup.html page while extending my base.html. The URL I have configured works, however it only pulls through the base.html template. I've checked the view, url and the signup.html template and I'm not sure what I'm getting wrong.
signup.html:
{% extends './layout/base.html' %}
{% load static %}
{% block content %}
<h1>Signup</h1>
{% endblock content %}
base.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% load static %}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lato:wght#300&family=Oswald&display=swap" rel="stylesheet">
<link rel="icon" href="{% static 'favicon.ico' %}">
<a target="_blank" href="https://icons8.com/icon/DpuVIej1M9Br/health">Health</a> icon by <a target="_blank"
href="https://icons8.com">Icons8</a>
<title>Your Health Now</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
urls.py:
from django.urls import path
from django.contrib.staticfiles.storage import staticfiles_storage
from django.views.generic.base import RedirectView
from . import views
app_name = 'HealthHub'
urlpatterns = [
path('signup/', views.signup, name='signup'),
path('favicon.ico', RedirectView.as_view(url=staticfiles_storage.url("favicon.ico")))
]
views.py:
from django.shortcuts import render
def signup(request):
return render(request, 'HealthHub/signup.html')
You should also define content block in base.html, so:
base.html:
...
<body>
{% block content %}
<h1> Hello World</h1>
{% endblock content %}
</body>
...
Then try it in signup.html, it will change content block to SignUp in h1 tag.
In base.html you should add an empty block where your other pages' HTML code will appear, it should be like this if you want the content ("Signup" h1) to appear under "Hello, world!":
base.html:
<body>
<h1>Hello, world!</h1>
{% block content %}
{% endblock content %}
</body>
registration and login page is working properly but mine like button is not working it doesn't highlight users who presses like button and also doesn't show the count of like .. I don't know why... Can somebody help me to solve this issue … it will be great help please help Thank you!
Views.py
from django.shortcuts import render, get_object_or_404, redirect
from datasecurity.models import Post
from django.urls import reverse
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
# Create your views here.
#login_required
def likes(request, pk):
post = get_object_or_404(Post, id=pk)
post.likes.add(request.user)
return HttpResponseRedirect(reverse('datasecurity:datasecurity', args=str(pk)))
def datasecurity(request):
allPosts= Post.objects.all()
context={'allPosts': allPosts}
def __init__(self, *args, **kwargs):
stuff = get_object_or_404(Post, id = self.kwargs['pk'])
total_likes = stuff.total_likes()
context['total_likes'] = total_likes
return render(request, 'datasecurity/data.html',context=context)
def blogHome(request, slug):
post=Post.objects.filter(slug=slug).first()
context={"post":post}
return render(request, "datasecurity/blogHome.html", context)
2.urls.py
from django.conf.urls import url
from . import views
app_name = 'datasecurity'
urlpatterns = [
url(r'^$', views.datasecurity, name="datasecurity"),
url(r'^datasecurity/(?P<slug>[^/]+)', views.blogHome, name='blogHome'),
url(r'^likes/(?P<pk>\d+)/', views.likes, name = "likes"),
]
Models.py
from django.db import models
from ckeditor.fields import RichTextField
from django.contrib.auth.models import User
# Create your models here.
class Post(models.Model):
sno=models.AutoField(primary_key=True)
title=models.CharField(max_length=255)
author=models.CharField(max_length=14)
slug=models.CharField(max_length=130)
timeStamp=models.DateTimeField(blank=True)
content=RichTextField(blank=True, null=True)
img = models.ImageField(blank=True, null=True, upload_to="dataimage/")
likes = models.ManyToManyField(User, related_name='likes')
#property
def total_likes(self):
return self.likes.count()
def __str__(self):
return self.title + " by " + self.author
data.html
<html lang="en" dir="ltr">
<head>
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<link
href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900"
rel="stylesheet"
/>
<meta charset="utf-8">
<title></title>
<!-- Bootstrap core CSS -->
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
<link rel="stylesheet" href="{% static 'css/datasecurity.css' %}">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=PT+Sans&display=swap"
rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?
family=Bebas+Neue&family=PT+Sans&display=swap" rel="stylesheet">
<link rel="canonical" href="https://getbootstrap.com/docs/5.0/examples/cover/">
<script async defer crossorigin="anonymous"
src="https://connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v9.0"
nonce="noEcH88O"></script>
<script async defer crossorigin="anonymous"
src="https://connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v3.2"></script>
</head>
<body>
<!-- End header -->
<div id="page-wraper">
<!-- Sidebar Menu -->
<div class="responsive-nav">
<div class="top-navbar">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<marquee><ul class="navbar-nav ml-auto">
<li class="nav-item"><a class="nav-link" href="{% url 'careforallapp:base'
%}">Home</a></li>
</ul></marquee>
</div>
</div>
</nav>
</div>
<section class="section about-me" data-section="section1">
<div class="container">
<div class="section-heading">
<h2>Welcome to Data Security</h2>
{% for post in allPosts %}
<div class="line-dec"></div>
<span
>This is a Bootstrap v4.2.1 CSS Template for you. Edit and use
this layout for your site. Updated on 21 May 2019 for repeated main menu HTML
code.</span>
</div>
<div class="left-image-post">
<div class="row">
<div class="col-md-6">
<div class="left-image">
{% if post.img %}
<img src="{{ post.img.url }}" alt="" />
{% endif %}
</div>
</div>
<div class="col-md-6">
<div class="right-text">
<h4>{{post.title}}</h4>
<h6>Article by {{post.author}}</h6>
<h2>{{post.datetime}}</h2>
<p>
{{post.content|safe | truncatechars:280}}
</p>
<from action = "{% url 'datasecurity:likes' pk=post.pk %}" method = "POST">
{% csrf_token %}
<button type="submit" name="post_id" class="btn"> Like </button> - {{
total_likes }} likes
</form><br><br>
<div class="white-button">
Read More
</div><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
{% endfor %}
There is no error when I debug the code .. may be it is logical error .. I really don't know .. can someone help me to find out the error
Thank you
I built a blog site. Although it works in css on other pages, it doesn't work on the category page. What can I do? I edited. thanks for your answers. It looks like your post is mostly code; please add some more details.
Here is my code:
settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static') ]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles/')
blog/views.py
def category_detail(request, cats):
category_posts=Blog.objects.filter(category_id=cats)
context = {
'cats': cats, 'category_posts': category_posts,
}
return render(request, 'post/category.html',context)
urls.py
from django.conf.urls.static import static
from django.urls import include, path
from blog.views import blog_detail, category_detail
from home.views import home_view, about_view
urlpatterns = [
url(r'^adminerdo/', admin.site.urls),
url(r'^$', home_view),
url(r'^about/$', about_view),
url(r'^(?P<slug>[\w-]+)/$', blog_detail , name= 'detay'),
url(r'^category/(?P<cats>[\w-]+)/$', category_detail, name='category'),
]
urlpatterns += static(settings.MEDIA_URL,document_root = settings.MEDIA_ROOT)
category.html
{% include 'header2.html' %}
<div class="blog_breadcrumb_wrapper">
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-12">
<div class="blog_breadcrumb_div">
<h3>{{ blog.title }}</h3>
</div>
</div>
</div>
</div>
</div>
<div class="blog_main_wrapper blog_toppadder60 blog_bottompadder60">
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-12">
<div class="blog_post_style2 blog_single_div">
<div class="blog_post_style2_img wow fadeInUp">
<img src="{{ blog.image.url}}" class="img-fluid" alt="">
</div>
<div class="blog_post_style2_content wow fadeInUp">
<h3>{{ blog.title }}</h3>
<div class="blog_author_data"><img src="https://via.placeholder.com/34x34" class="img-fluid" alt="" width="34" height="34"> {{ blog.user}}</div>
{{ cats }}
{% for blog in category_posts %}
{{ blog.category }}
{{ blog.title }}
{% endfor %}
</div>
</div>
</div>
</div>
</div>
</div>
{% include 'footer.html' %}
header2.html --- detail.html is working with it.
<!DOCTYPE html>
<!--
-->
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="tr">
<!--<![endif]-->
<!-- Begin Head -->
<head>
<title>tittle</title>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta name="description" content="Blog">
<meta name="keywords" content="">
<meta name="author" content="kamleshyadav">
<meta name="MobileOptimized" content="320">
<!--Start Style -->
<link rel="stylesheet" type="text/css" href="../static/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../static/css/font-awesome.css">
<link rel="stylesheet" type="text/css" href="../static/js/plugins/swiper/swiper.css">
<link rel="stylesheet" type="text/css" href="../static/js/plugins/magnific/magnific-popup.css">
<link rel="stylesheet" type="text/css" href="../static/css/style.css">
<!-- Favicon Link -->
<link rel="shortcut icon" type="image/png" href="../static/images/favicon.png">
</head>
I edited. thanks for your answers. It looks like your post is mostly code; please add some more details.
You have:
urlpatterns += static(settings.MEDIA_URL,document_root = settings.MEDIA_ROOT)
when your settings say:
STATIC_URL = '/static/'
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static') ]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles/')
Try:
urlpatterns += static(settings.STATIC_URL,document_root = settings.STATIC_ROOT)
EDIT after OP update:
So, you've set up django's static handling system, but you're not using it. Try:
{% load static %}
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}" type="text/css" />
etc.
I was editing the template to include a hyperlink. But when I do I get NoReverseMatch error.
Reverse for 'views.hello_world' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
The template file:
layout.html
{% load static from staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% static 'css/layout.css' %}">
</head>
<body>
<div class="site-container">
<nav>
Home [**Error here**]
</nav>
{% block content %}{% endblock %}
</div>
</body>
</html>
urls.py
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from . import views
urlpatterns = [
url(r'^courses/', include('courses.urls')),
url(r'^admin/', admin.site.urls),
url(r'^$', views.hello_world)
]
urlpatterns+=staticfiles_urlpatterns()
views.py
from django.shortcuts import render
def hello_world(request):
return render(request, 'home.html')
The line,
Home
when removed I don't get any error. But I add, the NoReverseMatch arises. What am I doing wrong?
You need to give the URL a name, and refer to that name in the url tag.
url(r'^$', views.hello_world, name='hello_world')
...
<a href="{% url 'hello_world' %}">
I have a problem with including css and js files. My index page works fine, but when I try to put the same code to the detail page it doesn't work, not even html wich I wrote on detail.html, just the include files from master.html work. What can be the problem?
master.html
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<link href="static/font.min.css" rel="stylesheet">
<link href="static/bootstrap.min.css" rel="stylesheet">
<link href="static/font-awesome.min.css "rel="stylesheet">
<link href="static/main.css" rel="stylesheet">
</head>
<body data-spy="scroll" data-target="#navbar" data-offset="0">
{% include "header.html" %}
{% include "carausel.html" %}
{% block h1 %}{% endblock %}
{% include "footer.html" %}
<script src="static/jquery.js"></script>
<script src="static/bootstrap.min.js"></script>
<script src="static/jquery.isotope.min.js"></script>
<script src="static/jquery.prettyPhoto.js"></script>
<script src="static/main.js"></script>
</body>
detail.html
{% extends "master.html" %}
{% block h1 %}
<div class="box first">
<div class="row">
<div class="container">
{% for question in latest_question_list %}
<div class="col-xs-12 col-sm-4 col-md-3">
<div class="center">
<h4>{{ question.naslov }} </h4>
<p>{{ question.opis }}</p>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}
{% block title %} Detail {% endblock %}
views.py
from django.shortcuts import render
from .models import Question
def index(request):
latest_question_list = Question.objects.all()
context = {'latest_question_list': latest_question_list}
return render(request, 'papers/index.html', context)
def detail(request, slug):
question = Question.objects.get(slug=slug)
return render(request, 'papers/detail.html', {'question': question})
urls.py
from django.conf.urls import include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.contrib import admin
urlpatterns = [
url(r'^$', 'papers.views.index', name='index'),
url(r'^admin/', include(admin.site.urls)),
url(r'^(?P<slug>[\w_-]+)/$', 'papers.views.detail', name='detail'),
]
urlpatterns += staticfiles_urlpatterns()
Use absolute paths for all your static links.
<link href="/static/....
<script src="/static/...