1👍
Theoretically you can create a view which has a wildcard as the URL. And then have the view lookup the various actually used URLs in the ArticlePage.
def pageView(request, url):
page = ArticlePage.objects.get(slug=url)
...
return page.content
With the URLs specified as:
urlpatterns += patterns('articles.views',
(r'^(?P<url>.+?)/$', 'pageView'),
) #Catch all URLs not yet matched and attempt to find them in the database.
at the end of your urls.py
.
And then you can use an HTML editor of some sort to create the actual content and whatnot.
So it is possible. However the question is do you want to?
It is possible to create a few of the pages on a website completely from scratch and storing the HTML in a database. Think small pages which are rarely updated but if updated change rigorously.
However, generally speaking a website has some structure. Something like blog posts, comments, polls, user registration and other interactive pages. Those pages cannot be described in a database field holding HTML.
Although if you do actually manage to do all that then I fear for your sanity because it must have been a painful and awkward road.
Hope this helps.
Update:
If you want to show a static HTML only page you normally just refer to them directly from the urls.py. Generally very few HTML is directly stored in databases. Most often you just store data in the database. If HTML is heavily being modified/saved/created/served from the CMS you just store it as an HTML file somewhere on the webserver.
Although one can certainly think of reasons to put HTML pages in the Database there is an equal many reasons as to why you shouldn’t. It all comes down to the specifics of the problem.
E.g. if you allow a user to create a comment with links/boldface/italics etc. you can save the word or //word// in the db and parse it every time. Or you can parse it once and just store the HTML in the database so you don’t have to parse it every time.
Same goes for larger pages although they generally have too much markup to be hand typed via the CMS every so often.
As for serving an HTML page directly via urls.py
:
E.g.
from django.views.generic import TemplateView
urlpatterns = patterns('',
(r'^foo/$', TemplateView.as_view(template_name='foo.html')),
)
Source: How do I go straight to template, in Django's urls.py?