How to fill a template without models? I use Django REST , python 3.4 , Angular JS .
Suppose there are 4 pages in the form of templates: main.html, page1.html, page2.html, page3.html .
The main page displays the list that is obtained from the database query. When you select any item, you must page1 , and display a list on it, also obtained from the results of the database query (the database is not Django), but taking into account the item selected on the main page, i.e. pass several parameters to REST , fill in the template page1.html results of the query and display the summary page. Further, when selecting an item, to carry out the same way to page2 , from it to page3 , etc.
Just make the links of the links like /page1/type=sometype&id=1 on the main page, on page1 - /page2/type=secondtype&id=6 etc? What type is better to use the class for processing requests - APIView ? Trying to use APIView , click on the link of the form /page1?id=1 Here is an example with no type parameter, only with id :
class SomeAPI(APIView): permission_classes = [permissions.AllowAny] def get(self, request, *args, **kwargs): if (request.GET.get('id',None)): ... # result = получаю из базы данных набор записей на основе id return Response({'res':result}, template_name="page1.html") in urls.py: url(r'^page1'), SomeAPI.as_view()
In the page1.html template
... <tr ng-repeat="item in res"> {{item}} ... Records are returned correctly (that is, there is no problem getting data from the database), but they are not displayed in the page1.html template, but on the page of the standard REST API template as a JSON-структуры .
{ "res": [ { "item": "1" }, { "item": "2" }, { "item": "3" }, { "item": "4" } ] } In fact, I need to combine the functionality of TemplateView + APIView . It would be similar, as on the main page, from the AngularJS controller to request the APIView JSON result using the GET method, and fill in the template . But for page1, page2, page3 you need to use id . Passing it with a GET request is not a problem, and APIView answer in an APIView too, but how do you send this id from the main page to the controller for page1 , for example? And how to fill in a template based on a JSON response?