render page is wrong - python

When I accessed upload_save method,basic.html was showed.
I wrote(changed into) in view.py like
def upload_save(request):
photo_id = request.POST.get("p_id", "")
if (photo_id):
photo_obj = Post.objects.get(id=photo_id)
else:
photo_obj = Post()
files = request.FILES.getlist("files[]")
photo_obj.image = files[0]
photo_obj.save()
return render(request, "registration/accounts/photo.html")
photos = Post.objects.all()
context = {
'photos': photos,
}
return render(request, 'registration/accounts/photo.html', context)
So,I naturally thought when I accessed upload_save method,photo.html would be showed.
In photo.html,I wrote
{% extends "registration/accounts/base.html" %}
{% block body %}
<div class="container">
{% for photo in photos %}
<h2 class="page-header">{{ photo.title }}</h2>
<div class="row">
<div class="col-xs-4">
<img class="img-responsive" src="/media/{{ photo.image1 }}">
</div>
<div class="col-xs-4">
<img class="img-responsive" src="/media/{{ photo.image2 }}">
</div>
<div class="col-xs-4">
<img class="img-responsive" src="/media/{{ photo.image3 }}">
</div>
</div>
<a class="btn btn-primary" href="{% url 'accounts:upload' photo.id %}">UPLOAD</a>
{% endfor %}
</div>
{% endblock %}
I wrote
base.html in photo.html ,but I cannot understand why photo.html's content is not show.
By Google Verification,I found only base.html was showed in my page.(So,photo.html could not be read)
How can I fix this?

You did not provide photos to your template. The {% for photo in photos %} is trying to loop over something that has not been provided. You need to add photos to the template context like so:
# ... rest of your view
photos = Post.objects.all()
context = {'photos': photos}
return render(
request, "registration/accounts/photo.html", context=context
)
Reference: render()

I think you did not include block body in base.html. if not included add these lines in base.html where you want to add photo.html content
{% block body %}
{% endblock %}
base.html should be look like this
{% load staticfiles %}
<html>
<head>
<title>Hello</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link href='//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
</head>
<body>
<div class="page-header">
<h1>Photo list</h1>
</div>
<div class="content container">
<div class="row">
<div class="col-md-8">
{% block body %}
{% endblock %}
</div>
</div>
</div>
</body>
</html>

Related

Unable to get through .is_valid() validation of Django for POST request for Images field

The POST request for images does not get validated on my form, when i created a new form it worked fine and was able to save the images. but going back to same old form i tried making the body part similar to the old one but got the same message even tried to check the console for form.errors but couldn't find anything.Still trying to figure out what is it that's missing in input as per the console log ValidationError[This field is required].
console log for the POST Request made
View.py function used to validate and get post
models.py
form.py ModelForm
main layout html template
<!DOCTYPE html>
<html lang="en">
<head>
<!-- <title>Encyclopedia</title> -->
<title>{% block title %} {% endblock %}</title>
<link rel="stylesheet" href="..\..\static\mywikiapp\style.css">
{% block head %}
{% endblock %}
</head>
<body>
<div class="main">
<div class="leftpart">
<h2 id="leftheading">Wiki</h2>
<div class="search_container_confinement">
<form>
<div class="searchcontainer">
<input type="text" name="q" placeholder="Search Encyclopedia">
</div>
</form>
</div>
<div class="listcontainer">
<ul id="left_col_li">
<li>Home</li>
<li>Create New Page</li>
<li>Upload Images</li>
<li>Random Page</li>
</ul>
</div>
<div class="navbar">
<div>
{% block navbar %}{% endblock %}
</div>
</div>
</div>
<div class="rightpart">
<!-- <h1>All Pages</h1>
<div>
<ul>
<li>Css</li>
<li>Django</li>
<li>Git</li>
<li>HTML</li>
<li>Python</li>
</ul>
</div> -->
{% block body %}{% endblock %}
</div>
</div>
</body>
</html>
The Template in which validation fails.The variable formimg is the modelform for imagefield passed rendered to the html to select mutiple images
{% extends "mywikiapp/layout.html" %}
{% block title %}
Add Images
{% endblock %}
{% block head %}
<style>
.rightpart{
/* border:black solid; */
display:grid;
place-items: center;
}
</style>
{% endblock head %}
{% block body %}
<div class="btn">
<form class="add_images" enctype="mutipart/form-data" name="Upload_Images" action="{% url 'mywikiapp:save_image' %}" method="POST">
<!-- <form class="add_images" enctype="multipart/form-data" name="Upload_Images" action="{% url 'mywikiapp:save_image' %}" method="POST"> -->
<div>
<input type="submit" value="Save Images">
{% csrf_token %}
{{formimg.management_form}}
{% for i in formimg %}
{{i}}
{% endfor %}
</div>
<!-- {{formimg}} -->
<!-- <input required name="images" type="file" multiple="multiple" name="images"> -->
</form>
</div>
{% endblock %}
The html form in which validation works without any errors.
<!DOCTYPE html>
<html>
<head>
<title>Upload images</title>
<style>
body {
height:100vh;
width:100vh;
}
.rightpart{
/* border:black solid; */
display:grid;
place-items: center;
height:100%;
width:100%;
}
</style>
</head>
<body>
<div class="rightpart">
<div class="btn">
<form class="add_images" enctype="multipart/form-data" name="Upload_Images" action="{% url 'mywikiapp:save_image' %}" method="POST">
<div>
<input type="submit" value="Save Images">
{% csrf_token %}
{{formimg.management_form}}
{% for i in formimg %}
{{i}}
{% endfor %}
</div>
<!-- {{formimg}} -->
<!-- <input required name="images" type="file" multiple="multiple" name="images"> -->
</form>
</div>
</div>
</body>
</html>

Not sure why data won't render from file into browser

The '/' route is returning 'Hello world'. However, the '/data' route will not return anything. I can't figure out why it won't render anything in the browser.
from flask import Flask, render_template
import requests
import logging
from flask_sqlalchemy import SQLAlchemy
from localStoragePy import localStoragePy
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
token = 'Czm5aFtxepvvE4jZddlOsKXiwOzJUfl1BiFW18BfUtsUPPTkZnA663WQ13oQMdEq'
BASE_URL = 'https://canvas.sfu.ca/api/v1/courses/62319/quizzes'
headers = {'Authorization': "Bearer Czm5aFtxepvvE4jZddlOsKXiwOzJUfl1BiFW18BfUtsUPPTkZnA663WQ13oQMdEq".format(token)}
auth_response = requests.get(BASE_URL, headers=headers)
#userStringFromLocalStorage = localStoragePy.getItem('auth_response')
#userFromLocalStorage = JSON.parse(userStringFromLocalStorage)
#print(userStringFromLocalStorage)
print(auth_response.json())
#logging.warning('this is a warning')
#app.route('/')
def hello_world():
return 'Hello world';
#app.route('/data')
def hello_world_cello():
data = [{
"id":164284,
"title":"Quiz 1",
"html_url":"https://canvas.sfu.ca/courses/62319/quizzes/164284",
"mobile_url":"https://canvas.sfu.ca/courses/62319/quizzes/164284?force_user=1&persist_headless=1",
"description":"",
"quiz_type":"assignment",
"time_limit":"None",
"timer_autosubmit_disabled":false,
"shuffle_answers":false,
"show_correct_answers":true,
"scoring_policy":"keep_highest",
"allowed_attempts":1,
"one_question_at_a_time":false,
"question_count":2,
"points_possible":2.0,
"cant_go_back":false,
"access_code":"None",
"ip_filter":"None",
"due_at":"None",
"lock_at":"None",
"unlock_at":"None",
"published":true,
"unpublishable":true,
"locked_for_user":true,
"lock_info":{
"missing_permission":"participate_as_student",
"asset_string":"quizzes:quiz_164284"
},
"lock_explanation":"This quiz is currently locked.",
"hide_results":"None",
"show_correct_answers_at":"None",
"hide_correct_answers_at":"None",
"all_dates":[
{
"id":53086,
"due_at":"2021-05-06T06:59:59Z",
"unlock_at":"None",
"lock_at":"None",
"title":"Entrepreneursity Test",
"set_type":"CourseSection",
"set_id":131870
}
],
"can_unpublish":true,
"can_update":true,
"require_lockdown_browser":false,
"require_lockdown_browser_for_results":false,
"require_lockdown_browser_monitor":false,
"lockdown_browser_monitor_data":"None",
"speed_grader_url":"https://canvas.sfu.ca/courses/62319/gradebook/speed_grader?assignment_id=630900",
"permissions":{
"manage":true,
"read":true,
"update":true,
"create":true,
"submit":true,
"preview":true,
"delete":true,
"read_statistics":true,
"grade":true,
"review_grades":true,
"view_answer_audits":false
},
"quiz_reports_url":"https://canvas.sfu.ca/api/v1/courses/62319/quizzes/164284/reports",
"quiz_statistics_url":"https://canvas.sfu.ca/api/v1/courses/62319/quizzes/164284/statistics",
"message_students_url":"https://canvas.sfu.ca/api/v1/courses/62319/quizzes/164284/submission_users/message",
"section_count":1,
"quiz_submission_versions_html_url":"https://canvas.sfu.ca/courses/62319/quizzes/164284/submission_versions",
"assignment_id":630900,
"one_time_results":false,
"only_visible_to_overrides":true,
"assignment_group_id":154901,
"show_correct_answers_last_attempt":false,
"version_number":3,
"has_access_code":false,
"post_to_sis":false,
"migration_id":"None"
}]
return render_template('pages/venues.html', areas=data);
venues.html looks like the following
{% extends 'layouts/main.html' %}
{% block title %}Fyyur | Venues{% endblock %}
{% block content %}
{% for area in areas %}
<h3>{{ area.id }}, {{ area.title }}</h3>
<ul class="items">
</ul>
{% endfor %}
{% endblock %}
main.html
<!doctype html>
<head>
<meta charset="utf-8">
<title>{% block title %}{% endblock %}</title>
<!-- meta -->
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width,initial-scale=1">
<!-- /meta -->
<!-- styles -->
<link type="text/css" rel="stylesheet" href="/static/css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="/static/css/layout.main.css" />
<link type="text/css" rel="stylesheet" href="/static/css/main.css" />
<link type="text/css" rel="stylesheet" href="/static/css/main.responsive.css" />
<link type="text/css" rel="stylesheet" href="/static/css/main.quickfix.css" />
<!-- /styles -->
<!-- favicons -->
<link rel="shortcut icon" href="/static/ico/favicon.png">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/static/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/static/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/static/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="/static/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="/static/ico/favicon.png">
<!-- /favicons -->
<!-- scripts -->
<script src="https://kit.fontawesome.com/af77674fe5.js"></script>
<script src="/static/js/libs/modernizr-2.8.2.min.js"></script>
<script src="/static/js/libs/moment.min.js"></script>
<script type="text/javascript" src="/static/js/script.js" defer></script>
<!--[if lt IE 9]><script src="/static/js/libs/respond-1.4.2.min.js"></script><![endif]-->
<!-- /scripts -->
</head>
<body>
<!-- Wrap all page content here -->
<div id="wrap">
<!-- Fixed navbar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">🔥</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>
{% if (request.endpoint == 'venues') or
(request.endpoint == 'search_venues') or
(request.endpoint == 'show_venue') %}
<form class="search" method="post" action="/venues/search">
<input class="form-control"
type="search"
name="search_term"
placeholder="Find a venue"
aria-label="Search">
</form>
{% endif %}
{% if (request.endpoint == 'artists') or
(request.endpoint == 'search_artists') or
(request.endpoint == 'show_artist') %}
<form class="search" method="post" action="/artists/search">
<input class="form-control"
type="search"
name="search_term"
placeholder="Find an artist"
aria-label="Search">
</form>
{% endif %}
</li>
</ul>
<ul class="nav navbar-nav">
<li {% if request.endpoint == 'venues' %} class="active" {% endif %}>Venues</li>
<li {% if request.endpoint == 'artists' %} class="active" {% endif %}>Artists</li>
<li {% if request.endpoint == 'shows' %} class="active" {% endif %}>Shows</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<!-- Begin page content -->
<main id="content" role="main" class="container">
{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}
<div class="alert alert-block alert-info fade in">
<a class="close" data-dismiss="alert">×</a>
{{ message }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
{% block content %}{% endblock %}
</main>
</div>
<div id="footer">
<div class="container">
<p>Fyyur © All Rights Reserved.</p>
{% block footer %}{% endblock %}
</div>
</div>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script type="text/javascript" src="/static/js/libs/jquery-1.11.1.min.js"><\/script>')</script>
<script type="text/javascript" src="/static/js/libs/bootstrap-3.1.1.min.js" defer></script>
<script type="text/javascript" src="/static/js/plugins.js" defer></script>
</body>
</html>
I am trying to return 'data' variable in the '/data' route. I am using Flask as my environment. I haven't created a database yet to store these.
Ok, i'm now home, i'll thanks for editing with the main.html
So, your error probably come from here
<li {% if request.endpoint == 'venues' %} class="active" {% endif %}>Venues</li>
<li {% if request.endpoint == 'artists' %} class="active" {% endif %}>Artists</li>
<li {% if request.endpoint == 'shows' %} class="active" {% endif %}>Shows</li>
You're asking flask to generate a url for venues, artist, and shows.
The problem is that you never define these routes, flask can't create a URL for something that doesn't exist.
You have two solution :
You define your href with a relative url : href="/artists" for example, this will lead to http(s)://{host}/artists
This is the good old html way, and it's working easily.
You can define temporary void routes for these, for example :
#app.route('/artists')
def artists():
return ''
This will return a blank page.
With that and the previous comments i leaved, you should be able to make that working.
You should have error on your Flask app, check it out if you can, even if the error code doesn't help you, it can help other people to understand what's wrong.
Tell me if that helped.

Django 1.9 - IOError at /login/

Sorry if you tried helping me when I asked this earlier. Had to delete that post because I thought the question was poorly written.
So I have a login view that when I click submit throws the Error:
Exception Type: IOError
Exception Value:
[Errno 22] Invalid argument: u"C:\\Users\\Me\\Desktop\\mysite\\templates\\{'user': <CustomUser: coco>}"
Traceback:
C:\Users\Me\Desktop\mysite\accounts\views.py in login
40. return render('all_posts.html', {'user': request.user}, context_instance=RequestContext(request))
Originally my login view I had:
return HttpResponseRedirect('/')
instead of the current:
return render('all_posts.html', {'user': request.user}, context_instance=RequestContext(request))
and the former sort of worked, in the since that it didn't throw any errors and directed me to the proper url. but in my template; {% if request.user.is_authenticated %} wasn't working.
So I changed it in the hopes of getting my template to display the current user's name (Welcome, coco!), instead now I get this new error.
Here is my views.py
def login(request):
"""
Log in view
"""
if request.method == 'POST':
form = AuthenticationForm(data=request.POST)
if form.is_valid():
user = authenticate(username=request.POST['username'], password=request.POST['password'])
if user is not None:
if user.is_active:
django_login(request, user)
return render('all_posts.html', {'user': request.user}, context_instance=RequestContext(request))
else:
form = AuthenticationForm()
return render_to_response('login.html', {
'authenticationform': form,
}, context_instance=RequestContext(request))
base.html
<div class="log_bar">
<ul>
{% if request.user.is_authenticated %}
<li>Welcome,</li>
<li>{{ user.username }}</li>
<li>|</li>
<li>Log Out</li>
{% else %}
<li>Please</li>
<li><a data-toggle="modal" data-target="#modal-login" href="">log in</a></li>
<li>or</li>
<li><a data-toggle="modal" data-target="#modal-register" href="">sign up</a></li>
{% endif %}
</ul>
</div><!-- /.log_bar -->
EDIT 1: Login Template
login.html
{% load staticfiles %}
{% load crispy_forms_tags %}
<div class="modal" id="modal-login">
<div class="modal-dialog">
<div class="modal-content">
<form enctype="multipart/form-data" method="post" action="login/">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title">Log In</h3>
</div>
<div class="modal-body">
{% csrf_token %}
{{ authenticationform|crispy }}
</div>
<div class="modal-footer">
<input type='submit' class="btn btn-primary" value="Log In" />
</div>
</form>
</div>
</div>
</div>
EDIT 2: all_posts.html
all_posts is empty right now. basically it just extends base.html. I'll post both.
all_posts.html
{% extends "base.html" %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
</html>
EDIT 3: urls.py
from django.conf.urls import url, include
from blog import views
from accounts.views import get_profile, login, logout, register
import accounts
urlpatterns = [
url(r'^textpost$', views.submit_textpost, name='textpost'),
url(r'^linkpost$', views.submit_linkpost, name='linkpost'),
url(r'^$', views.all_posts, name='all_posts'),
url(r'^all$', views.all_posts, name='all_posts'),
url(r'^new$', views.new_posts, name='new_posts'),
url(r'^all/top_hour$', views.top_posts_hour, name='top_hour'),
url(r'^all/top_day$', views.top_posts_day, name='top_day'),
url(r'^all/top_week$', views.top_posts_week, name='top_week'),
url(r'^all/top_month$', views.top_posts_month, name='top_month'),
url(r'^all/top_year$', views.top_posts_year, name='top_year'),
url(r'^all/top_beginning_of_time$', views.top_posts_all, name='top_beginning_of_time'),
url(r'u/(?P<username>[a-zA-Z0-9]+)$', accounts.views.get_profile, name='username'),
url(r'register$', register, name='register'),
url(r'^profile/(?P<username>\w+/$)', get_profile, name='profile'),
url(r'logout/$', logout, name='logout'),
url(r'^login/$', login, name='login'),
url(r'(?P<username>[a-zA-Z0-9]+)/$', views.get_sub, name='sub_url'),
url(r'(?P<username>[a-zA-Z0-9]+)/(?P<title_slug>[a-zA-Z0-9]+)/$', views.get_sub, views.title_slug, name='sub_post'),
url(r'^comments/', include('django_comments_xtd.urls')),
]
base.html full
Side Note* In my nav class="navbar navbar-fixed-left navbar-static-top", notice all the href's are empty, that's because if I try to populate them {% url 'new_posts' %} etc.. it will throws the same Traceback:
'function' object is not iterable. I don't know if it's related, but I thought I should mention. I'm not even concerning myself with that now, I don't want to get ahead of myself. I'm just trying to learn how to do proper login for now.
{% load staticfiles %}
{% load crispy_forms_tags %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="{% static 'css/base.css' %}">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
<TITLE>{% block title %}{% endblock %}</TITLE>
</HEAD>
<BODY>
{% block content %}
{% block navigation %}
<div class="navbar-wrapper">
<div class="post_button" style="width:58px; margin:0 auto;">
Submit a Post
</div> <!-- /.post_button-->
<div class="log_bar">
<ul>
{% if user.is_authenticated %}
<li>Welcome,</li>
<li>{{ user.username }}</li>
<li>|</li>
<li>Log Out</li>
{% else %}
<li>Please</li>
<li><a data-toggle="modal" data-target="#modal-login" href="">log in</a></li>
<li>or</li>
<li><a data-toggle="modal" data-target="#modal-register" href="">sign up</a></li>
{% endif %}
</ul>
</div><!-- /.log_bar -->
<nav class="navbar navbar-fixed-left navbar-static-top">
<div class="container-fluid">
<!-- Collect the nav links, forms, and other content for toggling -->
<ul class="nav navbar-nav ">
<li class="active">Home <span class="sr-only">(current)</span></li>
<li>All</li>
<li>New</li
<li class="dropdown">
Top<span class="caret"></span>
<ul class="dropdown-menu">
<li>hour</li>
<li>24 hrs</li>
<li>week</li>
<li>month</li>
<li>year</li>
<li>beginning of time</li>
<li role="separator" class="divider"></li>
<li>Custom Search</li>
</ul>
</li>
</ul>
</div><!-- /.container-fluid -->
</nav>
<div id="side_bar">
<form class="navbar-form navbar-static-top navbar-right" role="search" id="navBarSearchForm">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search">
<span class="input-group-btn">
<button type="submit" class="btn btn-default" id="search_btn">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</form>
</div><!-- /.side-bar -->
<button class="btn-block" id='hideshow' value='hide/show' style="display: block; height: 100%;"></button>
{% include 'register.html' %}
{% include 'login.html' %}
{% endblock %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> </script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"> </script>
<script type="text/javascript" src="{{ STATIC_URL }} /static/jquery.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }} /static/jquery.leanModal.js"></script>
{% endblock %}
</BODY>
</HTML>
The first argument of render must be request object, second template name, third context.
return render(request, 'all_posts.html', {'user': request.user})

What should I write for my detail view to inhert DB fields for my Django template?

I am new in Python. I have a problem with fetching DB fields to my Django template. File detail.html successfully extends my master.html, but it doesn't get anything I wrote under {% block h1 %} {% endblock %}
What should I write under views.py to make it work?
detail.html
{% extends "master2.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>
</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})
index.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>
</div>
{% endblock %}
{% block title %} Index {% endblock %}
master2.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" %}
{% include "nav.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>
</html>
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>
</html>
You loop over latest_question_list, but pass {'question': question} in the context
{% extends "master.html" %}
of index.html to be changed to
{% extends "master2.html" %}

Pygmented code showing up as a list

I'm using django-pygments and am trying to us it like so (base.html)
<!DOCTYPE html>
{% load pygmentify %}
<head>
<link rel="stylesheet" media="screen" href="{% static 'django_pygments/css/pygments_default.css' %}" type="text/css">
</head>
<div class="row">
<div id="mainbody" class="small-12 large-8 large-offset-2 columns">
<body>
{% pygment %}
{% block content %}
{% endblock %}
{% endpygment %}
</body>
</div>
<div id="sidebar" class="small-12 large-2 columns">
</div>
<div class="small-12 large-8 large-offset-2 columns">
{% block comments %}
{% endblock %}
</div>
<div class="small-12 large-2 columns">
</div>
</div>
Then I'm passing {{ post.content|safe }} into block content. The pigmented code comes out as such:
I've tried changing the <ol> tags in the source code to <ul> but obviously that wasn't the issue. I also turned passed linenos=False and True but that only made it more weird as the line numbers aren't lined put correctly.
Anyone know what I might be doing wrong?
Apparently there was a problem with my css style sheet. I tried changing it and now it looks normal.

Categories

Resources