how to create view for django root module - django

I have a django project with nested smaller apps call: blog, research, report.
I would like to create a view at the root folder (django project level) so that it displays all the blog, research and report posts.
what can i do?
usually i wire the django project urls so that the request '' go to the blog home view. Now i dont want it to be wired that way anymore. I would like that the '' go to a page (i think at django project root level) that can render all blog, research and report articles.

I just start a new app to handle those 3 types, step by step as usual.

Related

How to build API that will return HTML for the site and JSON for other clients

I have started learning DRF just a while ago and had a little question -
how can I code one API that will return HTML for the site that I am currently working on and return JSON format for other "clients"(e.g. mobile apps, desktop, etc)?
I have tried to search for this information, but didn't found any answering content.
The only way I see is to create default Django views for the site and create separated API's for other requests. Can anybody tell me if I am right and need to do so, or there is some code that is solving my problem?
Ultimately, you can think of it as a whole separate set of views, urls and instead of models you have a serializer. Within you're app you can create an API folder. Within that directory you will need to have an '_ _ init _ _.py', 'urls.py', 'views.py' and a 'serializers.py'. Its analogous to creating a standard url, view, model structure to display an HTML page, but without the HTML template. Make distinct urls for the serializers too. For example for login do something like this:
path('my_app_api/login', serializer_view)
Youtube has tons of videos if you search django rest framework

Building user area and site admin - Django - CMS

I am a begginer with Django. I read a book and then I practiced building a real estate project which is working fine. Now I am going to create the admin area, for example, for the site editor to post articles, set posts as paid, edit layout texts ...
I used Django 1.9.10 to build the project. I have been reading and looks like I will need do use Django CSM. Do I have to start a new project or is it possible to change my Django project using django cms?
Thank you
Why not using the built-in Admin module for that part?
https://docs.djangoproject.com/en/1.10/intro/tutorial02/#explore-the-free-admin-functionality

How to link python file with the html file

I've started one new django project. I've linked the HTML file in the django's admin page. When I click view site in the admin page the html file has open.
In this html file there is a register button. When I click it, the html form will open for fill the details to register for signup.
When I filled the details and click submit button, the python file (signup.py) has to show the data and save in db. But I got the error
"Page not found (404)
Request Method: GET
Request URL: http://10.95.228.84:8000/signup.py?CID=aasa&user_name=sadsad&User_email=sasa%40gmail.com&DOB1=2016-08-30&Password11=sasasa&Password12=sasasa&submit=submit"
Please let me know how to link this signup.py file with this html.
What's going on is that you have a GET request to a URL that happens to be named 'signup.py' followed by the form parameters. This is not how Django fundamentally operates. Django forms automatically 'takes care of' saving new entries into the database if the forms are valid (assuming you are using a correct model and ModelForms).
I can't tell what your models are like or your urls, but I would suggest:
1) Creating Models in models.py that accurately match what you are trying to save into your database (if you haven't already)
2) Creating a view in views.py and that will link to a template (that you will need to create) displaying the data that is being saved into your database
3) Creating a url for this new view you created in urls.py
4) Editing the view that is currently handling the signup form to redirect your your view if the form is valid.
I would suggest looking at the Django tutorial. Going through it once or twice will solidify the basic workflow of using Django. This tutorial also has a solid tutorial on simple forms.
Django Tutorial
Simple Django Forms

App with multiple categories in Django CMS

we are trying to migrate a project written with Drupal to Django CMS and we faced a problem with article module. Our site is divided in sections and we have a news module installed in every section with a category, url structure is looking like this:
/section1
/news-category1
/section2
/news-category2
/etc..
This is the same news module, just split in categories (some news articles can pop up in multiple sections, in this case one section is chosen as base to form unique article URL). The only one method I found makes this structure:
/news
/caregory1
/category2
/etc...
Which is not good for us as we would prefer to keep the current URL structure for SEO purposes. Is there a correct way to implement this in Django CMS beside creating each section as a module and plugging in in to a page? Or can I some-how install the same module to multiple pages and pass the section information to it?
One way to do this I found myself would be to plug-in the same module to every page it will be on and then have it to parse the path of the page to figure out it's category. Not super-officiant but might work. Not sure if there is any other way.

Integrate existing blog code into Django-CMS?

If I already have a blog app done with Django and I want to use it with my new Django CMS site, is it okay to simply drop it into my new Django CMS project as a decoupled app and match anything /blog/ to the blog app as apposed to a Django CMS plugin? I guess what I need to know is when is it best to write my Django app as a plugin vs an entire app?
Thx
JeffC
Yes, but you don't just drop it into the urls.py, instead you can write an AppHook to tie your blog's URL scheme to a particular page in your CMS.
Plugins on the other hand are useful if you want to inserts particular aspects of you app into other page's placeholders - for example to show your latest 3 posts on the frontpage.
You might also want to include your blog's paths in a breadcrumb or menu on your site - in that case you need to write a custom Menu too.
Finally, it might also be useful to make use of django cms's placeholders in you blog model. His would allow you to post a variety of content via plugins.