Manage pages in database in Django 1.5 - python

Is it possible to organize your urls.py with a Django model? I would like to create a admin interface to manage pages, and output the pages as links in the navigation, but I will run into problems with parameters. The pages should take different parameters. Am I on the wrong track? Is it possible to find a project which has already done it on Github or other open source code repository sites?

Django comes with a flatpages app that does what you need.

I guess Django CMS does that. It holds the whole site structure in DB.

Related

Overriding Django admin vs creating new templates/views

I am a total noob with Django, I come from the PHP world and I am used to doing things differently.
I'm building an app and I want to change the way the backend looks, I want to use Bootstrap 4 and add a lot of custom stuff e.g. permission based admin views, and I was wondering what is the best practice, or how do more experienced django devs go about it?
Do they override all the django.contrib.admin templates, or do they build custom templates and login/register next to it, and use the django.contrib.admin only for the superuser?
What is the django way?
Django admin is intended for administration purposes. For all intents and purposes it is a direct interface to your database. While I have seen some people building customer facing interfaces using admin, this is most definitely not the way to make a general Django web application.
You should define views for your models. You can use built-in APIs to login and authenticate users. You should most likely restrict access to admin to internal users only.
As for templates, the modern way of doing things is to dynamically fetch data using an API and do all the UI logic in Javascript. Django can be used very well to provide an API to a frontend. Look into Django REST Framework. The basic idea is to write serializers for your models and have view functions serve the serialized data to the front end.
You could go the old school way and render your pages using templates of course. In that case your views would render templates using data provided by your models.
Yes. The admin pages is actually for administering the webpage. For user login and registration you create the templates. However, if you want your backend to look different then you can tweak the template for the admin page, admin login page as well. And you can also have permission based admin views. It's okay to over ride the defaults as long as you know what you're doing. Hope that helped.

Django project with independent apps or project linking to multiple django projects?

i´m quite new to django. My question is probably very simple but i´m struggling on what is the best approach. I am trying to develop a web platform for work. It is supposed to have a homepage that shows four different services. By clicking in one of those services a login page should be displayed entering what i think it should be a different project because it is going to have their own views, users and database. The question is how do i build a homepage like this? What is the best approach? If having four django projects in a homepage is the way how do i do that?

How to create empty wordpress permalink and redirect it into django website?

I need to do such thing, but I don't even know if it is possible to accomplish and if so, how to do this.
I wrote an Django application which I would like to 'attach' to my wordpress blog. However, I need a permalink (but no page in wordpress pages section) which would point to Django application on the same server. Is that possible?
You can use the "Page links to" wordpress plugin to point to any url: https://wordpress.org/plugins/page-links-to/
There are many ways to do this. You will have to provide more info about what you are trying to accomplish to give the right advise.
make a page with a redirect (this is an ugly solution in seo and user perspective)
handle this on server level.
load your Django data with an ajax call

How can I copy CMS pages from a development site to a live site?

I've been integrating Django CMS to a Django project that has been in production already for over a year. As part of my development activities, I've converted to CMS pages those pages that used to be static content before I added Django CMS. My development database now contains pages that I would like to copy to the live site rather than require that project staff recreate these pages on the live site.
I have searched the Django CMS documentation but did not find a command for this. I've also searched the issues on github, the questions on SO and the Django CMS google groups. The only thing I've found is this discussion from 3 years ago. The discussion mentions using dumpdata to dump the cms models. I've tried it. The dump contains information about the pages (for instance, who created the page and when) but it does not contain the contents of the pages.
The live site has data that must be preserved. So I cannot perform a database level dump on the development site and restore on the live site, as this would erase or overwrite data that already exists on the live site.
I'm using Django 1.7 and Django CMS 3.1.0.
The discussion you refer to predates the 3.x series. Perhaps doing a dumpdata for the models associated with the cms application was the way to go 3 years ago, but, as you discovered, it does not work now.
I actually recommend trying the following steps on a mirror of your live site first so that any surprises can be taken care of ahead of the real operation. If you run into trouble on the mirror, you can take your time figuring the problem. Once you are ready to modify your live site, before you do anything, you should backup your database. Better safe than sorry. Also, the codebase on the site should be updated to reflect your development version before you try moving data around.
You can use these steps:
Inspect your INSTALLED_APPS setting and make a list of those apps that are CMS plugins and of the applications these plugins depend on. You may need to consult the installation instructions of some of the plugins to recall what depends on what.
Once you have the list you can issue a dumpdata command on your development site with cms and the applications you identified. For my site, I have to do:
python manage.py dumpdata --natural-foreign cms filer \
cmsplugin_filer_file cmsplugin_filer_folder cmsplugin_filer_link \
cmsplugin_filer_image cmsplugin_filer_teaser cmsplugin_filer_video \
easy_thumbnails djangocms_text_ckeditor > data.json
If you also have created custom permission settings for Django CMS, you may need to edit data.json to remove some or all of the custom settings. In my case I had a cms.PageUserGroup instance that I had created on my dev site. It referred to a group that does not exist on the live site and so I had to remove this instance from the data.json dump. Otherwise, the loaddata command in the next step failed with an integrity error.
You then copy data.json to your live site and issue python manage.py loaddata data.json.
If you have any files you've added to your media directory on your development site to create your CMS pages, you also need to copy them over to your live site.
I've used the procedure above to move data from my development site to a live site, with no discernible problem.
Caveats
The procedure above is meant to be a one time deal. It won't work if you continue making changes to your development pages and then try to migrate them over to your live site.
I've mentioned issues with permissions in the steps above. You are least likely to run into permission issues if you have CMS_PERMISSIONS set to False. If set to True, then you may have to edit your dump like instructed above before loading it on the live site. If you've done heavy customization of the permission scheme and have a whole bunch of PageUserGroup instances and a bunch of pages with special permissions, etc., then you are likely to run into major difficulties. I don't know a solution short of undoing all this customization, or editing the dump by hand to make it match your live site. The problem is due to the fact that the procedure above does not dump the authentication models (of django.contrib.auth). If you are in a situation where you can safely load them on the live site, then adding them to the dump would probably do the trick. However, when you have a live site that has been in production and where the authentication data has changed over time, you cannot just load the authentication models from the development site as this would overwrite some of the records (e.g. "admin"'s password would change to the one stored in the development database).
The method above does not move any of the pages' history. It is recorded with reversion. If you wanted to move the page's history, you'd have to add reversion to the list of apps to dump but I'm pretty sure it could have undesirable side-effects: it could also affect the data that reversion records for other apps that use it in the project. (In effect it would change or erase history of other apps.)
To copy CMS pages from a development site to a live site you could use Django CMS Transfer:
https://github.com/django-cms/djangocms-transfer
Django CMS Transfer is a package that allows you to export and import plugin data from a page or a placeholder.
It works pretty well for simple tasks like exporting plugins' content from a page and then importing it to another site.
However, it does not support foreign-key relations and won't import or export related data.
The Django CMS Association endorses this project.

Django - managing multiple pages with multiple fields

I am using Django for developing a website and I want to allow my staff to be able to add/edit/delete pages with multiple text fields. I am planning to use Django's admin framework for this as the staff is a non-technical one.But I have no clue on how to go about doing this so that people can login and edit the contents on these pages whenever they want.
Also, my site will be receiving around 1500 hits per day. I don't want to embed these pages in static templates (so that I can allow my staff to edit it). Will loading this data at runtime slow down my site. I am using a Servint VPS server.
Thanks
niting
Follow the Django tutorial, replacing the concept of Polls with Pages, and Choices with Content blocks and you'll be most of the way there (Django's built in Admin will allow you to edit these models).
For a more advanced CMS based on Django take a look at either Django CMS or FeinCMS.

Categories

Resources