<s> from django . contrib . flatpages . models import FlatPage <EOL> from django . template import loader , RequestContext <EOL> from django . shortcuts import get_object_or_404 <EOL> from django . http import HttpResponse <EOL> from django . conf import settings <EOL> from django . core . xheaders import populate_xheaders <EOL> DEFAULT_TEMPLATE = '<STR_LIT>' <EOL> def flatpage ( request , url ) : <EOL> """<STR_LIT>""" <EOL> if not url . startswith ( '<STR_LIT:/>' ) : <EOL> url = "<STR_LIT:/>" + url <EOL> f = get_object_or_404 ( FlatPage , url__exact = url , sites__id__exact = settings . SITE_ID ) <EOL> if f . registration_required and not request . user . is_authenticated ( ) : <EOL> from django . contrib . auth . views import redirect_to_login <EOL> return redirect_to_login ( request . path ) <EOL> if f . template_name : <EOL> t = loader . select_template ( ( f . template_name , DEFAULT_TEMPLATE ) ) <EOL> else : <EOL> t = loader . get_template ( DEFAULT_TEMPLATE ) <EOL> c = RequestContext ( request , { <EOL> '<STR_LIT>' : f , <EOL> } ) <EOL> response = HttpResponse ( t . render ( c ) ) <EOL> populate_xheaders ( request , response , FlatPage , f . id ) <EOL> return response </s>
