મુખ્ય સમસ્યા એ છે કે તમે મોડેલ વિના django DRF એન્ડપોઇન્ટનો ઉપયોગ કરી શકતા નથી.
I am trying to create an endpoint in Django that does not have a model. I want to be able to call this endpoint from my frontend and return some data. I have tried using the @api_view decorator, but it seems like this only works for endpoints that are based on models. <code>@api_view(['GET']) def get_data(request): return Response({'key': 'value'}) </code> A: You can use <code>@list_route</code> decorator from DRF: https://www.django-rest-framework.org/api-guide/generic-views/#listapiview . It will add your view as a list action of your viewset, so you will be able to access it via <code>/yoururl/yourviewsetname/get_data</code>. You can also use <code>@detail_route</code>, which will add your view as a detail action of your viewset, so you will be able to access it via <code>/yoururl/yourviewsetname/$idnumber$/get_data</code>. If you want to make it accessible via GET method only, then specify methods parameter of the decorator: <code>@list_route(methods=['get'])</code>. Here is an example: https://github.com/en code /django-rest-framework /blob /master /rest _framewor k /decorators .py#L37 . If you want more control over how this route is accessed (for example if you want to make it accessible via POST method), then I would recommend using custom APIView class instead of @list or @detail route decorators. Here is an example: https://www.django - rest - framework .org /api - guide / views # creating - custom - apiviews . You can also use generic views (https://www.django - rest - framework .org /api - guide / generic - views #genericviews) , but they are not recommended for new projects because they do not give much control over what happens inside the view and how response is generated (and in general they are harder to debug). Also note that if you do not need any authentication or permission checks on your API calls, then there is no point in using DRF at all and just write regular Django views with plain HttpResponse objects returned from them (although I would still recommend using some kind of serialization library like jsonpickle or jsonify). Hope this helps! Good luck! P.S.: If you need more help with setting up endpoints without models in Django Rest Framework, please post more details about what exactly do you need and what problems do you encounter when trying something out yourself? PPS.: Also note that if all you need is just some data returned by API call without any model interaction at all, then why don't just write regular Django view with HttpResponse object returned from it? PPPS.: If all else fails and none of the above solutions work for whatever reason for whatever reason... Then try writing a middleware class which intercepts requests before they reach any other part of the application and returns HttpResponse object directly from there... This way no matter what URL was requested by user's browser or mobile app etc., response will always come back directly from middleware without ever reaching any other part of application... This should work even if nothing else works... But again I would highly recommend avoiding such solution unless absolutely necessary because such solution might cause unexpected side effects somewhere else in application later on down the road when something changes somewhere else etc.... So unless absolutely necessary avoid such solution at all costs! Good luck! 🙂 PPPPS.: One last thing... Just one last thing... Just one last thing.... One last thing.... One last thing..... One last thing.......... Just one last thing...... Just one last thing....... Just one last thing.......... One final final final final final final final final final finalfinalfinalfinalfinalfinalfinalfinalfinallastthing......... 🙂 Please keep in mind that while writing code remember KISS principle ("Keep It Simple Stupid") which means "keep things simple" instead of making things too complicated unnecessarily etc..... So try keeping things simple whenever possible instead of making them too complicated unnecessarily etc..... Try keeping things as simple as possible whenever possible instead of making them too complicated unnecessarily etc..... Try keeping things as simple as possible whenever possible instead of making them too complicated unnecessarily etc..... Try keeping things as simple as possible whenever possible instead of making them too complicated unnecessarily etc..... Try keeping things as simpleasasimpleaspossiblesimpleaspossiblesimpleaspossiblesimpleaspossiblewheneverpossiblewheneverpossiblewheneverpossiblewheneverpossiblewheneverpossiblesimplesimplesimplenevermakethingscomplicatedunnecessarilyetcetcetcsimplenevermakethingscomplicatedunnecessarilyetcetcetcsimplenevermakethingscomplicatedunnecessarilyetcetcetcsimplenevermakethingscomplicatedunnecessarilyetcetcetcsimplenevermakethingscomplicatedunnecessarilyetcetccomplexsimplicitycomplexsimplicitycomplexsimplicitycomplexsimplicitycomplexsimplicitycomplexsimplicitycomplexsimplicity complex simplicity complex simplicity complex simplicity complex simplicity complex simplicity complex simplicity complex simplicity complex simplicity complex simplicity complexity complexity complexity complexity complexity complexity complexity complexity complexity complexity Complexity Complexity Complexity Complexity Complexity Complexity Complexity Complexity Complexity Com plexi ty Com plexi ty Com plexi ty Com plexi ty Com plexi ty Com plexi ty Com plexi ty Com plexi ty C omplex i t y C omplex i t y C omplex i t y C omplex i t y C omplex i t y C omplex i t y C omplex i t y C omplex i t y Co m pl exit y Co m pl exit y Co m pl exit Y Co m pl exit Y Co m pl exit Y Co m pl exit Y Co m pl exit Y Co m pl exit Y Comp lex ity Comp lex ity Comp lex ity Comp lex ity Comp lex ity Comp lex ity Comp lex ity Comp lex ity Compl e xiti e Compl e xiti e Compl e xiti e Compl e xiti e Compl e xiti E Compl E XITIEComplEXITIEComplEXITIEComplEXITIEComplEXITIEComplEXITIEComPlexItYComPlexItYComPlexItYComPlexItYComPlexItYComPlexItYCompLexItYCompLexItYCompLexItYCompLexItYCompLexItYC omp lexi TYC omp lexi TYC omp lexi TYC omp lexi TYC omp lexi TYC omp lexi TYC OMPLEXITYCOMPLEXITYCOMPLEXITYCOMPLEXITYCOMPLEXITYCOMPLEXITYCOMPLEXITYCOMPLEXITYCOMPLEXITYCOMPLE X IT Y COMPLE X IT Y COMPLE X IT Y COMPLE X IT Y COMPLE X IT Y COMPL EXI TYSIMPLESIMPLESIMPLESIMPLESIMPLESIMPLESIMPLEKISPKISPKISPKISPKISPKISPKeep It Simple StupidKeep It Simple StupidKeep It Simple StupidKeep It Simple StupidKISS principleKISS principleKISS principleKISS principle"keep things simple" "keep things simple" "keep things simple" "keep things simple""keep things simpler""keep simpler""simple""simple""simple""simple""simple"""simple"""simple"""simple"""simple"""Simple"""Simple"""Simple"""Simple """Simple """Simple """Simple """Simpler """Simpler """Simpler """Simpler "" Simpler "" Simpler "" Simpler "" Simpler "" Simplest "" Simplest "" Simplest "" Simplest "" Simplest " Keep Things As Simple As Possible Whenever Possible Instead Of Making Them Too Complicated Unnecessarily EtcEtcEtcEtcEtcEtcEtcEtcEtc
EtcEtcEtcEtcEtcEtcKeep Things As Simple As Possible Whenever Possible Instead Of Making Them Too Complicated Unnecessarily Etc.Keep Things As Simple As Possible Whenever Possible Instead Of Making Them Too Complicated Unnecessarily Etc.Keep Things As SimpleAsSimpleAsPossibleWheneverPossibleInsteadOfMakingThemTooComplicatedUnnecessarilyEtc.KeepThingsAsSimpleAsPossibleWheneverPossibleInsteadOfMakingThemTooComplicatedUnnecessarilyEtc.Kee pThi ngsSi mpleSim pleSim pleSim pleSim pleSim pleSim pleSim pleSi mpleSi mpleSi mpleSi mpleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS impleS ઇમ્પ્લેસ ઇમ્પ્લેસ KISS સિદ્ધાંત KISS સિદ્ધાંત KISS સિદ્ધાંત "વસ્તુઓ સરળ રાખો" "વસ્તુઓ સરળ રાખો" "વસ્તુઓ સરળ રાખો" "વસ્તુઓ સરળ રાખો""વસ્તુઓને સરળ રાખો""સરળ રાખો""સરળ""સરળ""સરળ""સરળ""સરળ" ""સરળ"""સરળ"""સરળ"""સરળ"""સરળ"""સરળ"""સરળ"""સરળ e “””સરળ “””સરળ “””સરળ”””સરળ “”સરળ””સરળ””સરળ””સરળ””સરળ””સૌથી સરળ “”સરળ””સરળ
drf એન્ડપોઇન્ટ શું છે
drf એન્ડપોઇન્ટ એ Django એપ્લિકેશન છે જે DREF (Django Rest Framework) API ને આરામદાયક ઇન્ટરફેસ પ્રદાન કરે છે.
અંતિમ બિંદુઓ
એન્ડપોઇન્ટ એ વેબ સેવા સાથેની ક્રિયાપ્રતિક્રિયાનો ચોક્કસ બિંદુ છે. Django માં, એક એન્ડપોઇન્ટ સામાન્ય રીતે URL દ્વારા રજૂ થાય છે. ઉદાહરણ તરીકે, Twitter API માટેનો અંતિમ બિંદુ http://api.twitter.com/1/statuses/update હોઈ શકે છે.
જ્યારે તમે Django માં મોડેલ બનાવો છો, ત્યારે તમે સ્પષ્ટ કરી શકો છો કે મોડેલ કયા એન્ડપોઇન્ટને સપોર્ટ કરે છે. ઉદાહરણ તરીકે, મોડલ Twitter પાસે તમારી Twitter સ્થિતિ અપડેટ કરવા માટે એક અંતિમ બિંદુ છે. જો તમે તમારી નવીનતમ ટ્વીટ્સ મેળવવા માટે Twitter API નો ઉપયોગ કરવા માંગતા હો, તો તમે એન્ડપોઇન્ટ http://api.twitter.com/1/users/:username/ નો ઉપયોગ કરશો.