1
Should I setup an API and then have my other apps just interact with that?
You should create an API apps to put all your api in it.
Then I would create another app which will display views and forms for authors to actually create blogposts and which would send http requests to the api.
It depends, I used to do like what you said, but now I find out I don’t actually have to write any code in the views.py
For instance, You have a blog project.
- Create two app, one is api, the other is blog.
-
Set your model in blog like this.
class Blog(models.Model): blog_title = models.CharField(max_length=30, blank=True) blog_content = models.CharField(max_length=140)
-
In api app, use django-rest-framework to create class BlogList(generics.ListCreateAPIView) and class BlogDetail(generics.RetrieveUpdateDestroyAPIView) or other APIView and Serializers to handle CRUD for your blog so your don’t have to write any code in blog’s views.py
-
I will recommend to use Ajax to handle the form instead of django build-in form api. Like CRUD the blogs, just send Ajax call to api/blogs(you handle it in your APIView, use django-rest-framework to handle which field is read only or any other porperty.), sign up or sign in just call api/users. django form api is complicated if you have lots of form and you can’t reuse it if you create a mobile app or use in other platform
Would it be better to take care of all of this within the same API app somehow?
Yes, it’s easy to maintain your code like I said above.