views:

37

answers:

2

I'm attempting to write my first CMS in Django. So far I have managed to get a system up and running similar to flatpages but a little more flexible. I have two questions about how I'm approaching the structure of the CMS:

Firstly, I am storing HTML tags with the text content in a Postgres database. I've seen a lot of post'ers saying that this shouldn't be done for security reasons. If HTML should not be stored with the text then how do you embed information like bold typing, paragraph and image tags into the content?

Secondly, I have tried checking numerous content management systems (mainly PHP ones) on how they deal with directory structures. For instance, I might have a programming page which appears within the 'computers' category. In a static page I would just create a directory called 'computers' and place my static programming page inside that directory. How do I model directory structures like that inside a CMS? I can't find any info anywhere on the underneath structures of CMS's.

Thanks for any advice....

+1  A: 
  1. Storing HTML tags is not inherently unsafe. You just have to scrub them of dangerous content before putting them in the database.

  2. Your page model will need to include information about the category. Then when displaying a category, you'll query your pages by category to get all the "computer" pages to display on the computer page.

Ned Batchelder
A: 

Do split this in 2 separate questions in the future.

  1. Storing HTML is fine. When you output it be sure to use |safe in the templates. If you really want to be picky, you can avoid storing by using http://en.wikipedia.org/wiki/Textile_%28markup_language%29 or http://en.wikipedia.org/wiki/Markdown. They are wysiwig editors out there that do all your trouble.

  2. You can create a Category model and all your pages with have a ForeignKey to this model. One of the most flexible solutions I found was to use tags, so a page can have multiple tags and thus fall under multiple 'categories' http://code.google.com/p/django-tagging/

Hope this helps.

Tudorizer
Thank you Tudorizor. There seems to be a big lack of the 'inbetween' info for programming in Django. There is never any guidance as to how things like CMS's are structured and then when somebody asks a question the response (like with my HTML one) is usually something like "you should never, ever put HTML in a database". This kind of shuts out intermediate programmers and gives no help for beginners to improve.
Boragora
There are no many docs, because there are no constrains imposed. It's up to you. Don't be afraid of making a wrong choice, especially if you do TDD.
Tudorizer