djapasteのソース

settings.pyとurls.pyは省略
djapaste/syntax/views.pyは書いてません。

これ使ってます:-)
dp.SyntaxHighlighter - free JavaScript syntax highlighting
http://www.dreamprojections.com/SyntaxHighlighter/

djapaste/syntax/urls.py


from django.conf.urls.defaults import *
from django.views.generic import list_detail, create_update
from syntax.models import Paste

queryset = dict(queryset=Paste.objects.all())
model = dict(model=Paste)

urlpatterns = patterns('',
(r'^$', create_update.create_object, model),
# (r'^list/$', list_detail.object_detail, queryset)
(r'^(?P<object_id>\d+)/$', list_detail.object_detail, queryset),
)

djapaste/syntax/models.py


from django.db import models

SYNTAX_TYPE = (
('py', 'Python'),
('html', 'HTML'),
('js', 'JavaScript'),
)

#TERM_TYPE = (
# (,),
# (,),
# (,),
#)

class Paste(models.Model):
name = models.CharField(maxlength=16)
title = models.CharField(maxlength=32)
syntax = models.CharField(maxlength=4, choices=SYNTAX_TYPE)
code = models.TextField()
created = models.DateTimeField(auto_now=True)
# term = models.SmallIntegerField(choices=TERM_TYPE)

class Admin:
pass

class Meta:
pass

def __str__(self):
return self.title

def get_absolute_url(self):
return '/djapaste/%d/' % self.id

djapaste/template/syntax/base.html


{% comment %}
vim: syntax=htmldjango
{% endcomment %}

<html>
<head>
</head>
<body>
{% block contents %}
{% endblock %}
{% block syntaxhighlighter %}
{% endblock %}
<body>
</html>

djapaste/template/syntax/paste_form.html


{% comment %}
vim: syntax=htmldjango
{% endcomment %}

{% extends "syntax/base.html" %}

{% block contents %}
<form method="post" action='.'>
<p><label for="id_title">title</label>{{ form.title }}</p>
<p><label for="id_code">code</label>{{ form.code }}</p>
<p><label for="id_syntax">syntax</label>{{ form.syntax }}</p>
<p><label for="id_name">name</label>{{ form.name }}</p>
<input type='submit' value="paste"/>
</form>
{% endblock %}

djapaste/template/syntax/paste_detail.html


{% comment %}
vim: syntax=htmldjango
{% endcomment %}

{% extends "syntax/base.html" %}

{% block syntaxhighlighter %}
<link type="text/css" rel="stylesheet" href="/static/css/SyntaxHighlighter.css"></link>
<script language="javascript" src="/static/js/shCore.js"></script>
<script language="javascript" src="/static/js/shBrushJScript.js"></script>
<script language="javascript" src="/static/js/shBrushSql.js"></script>
<script language="javascript" src="/static/js/shBrushXml.js"></script>
<script language="javascript" src="/static/js/shBrushPython.js"></script>
<script language="javascript" src="/static/js/shBrushCss.js"></script>
<script language="javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
{% endblock %}

{% block contents %}
<div>{{ object.title }} by {{ object.name }}</div>
<div>{{ object.created }}</div>
<textarea name="code" class="{{ object.syntax }}">{{ object.code }}</textarea>
{% endblock %}