Hi I am looking to create a SOAP service within my Django App, but have come across a few hitches.
Firstly I have been able to successfully follow the soaplib Hello World tutorial (google "soaplib hello world" since I only can use 1 hyperlink as this is my first question) which uses a CheryPy WSGI server to run the service, and the soaplib client to initiate a SOAP request.
I am having trouble converting that into a service within Django through following this djangosnippets snippet. Currently I am using the Django development server.
Viewing http://localhost:8000/hello_world/ in the browser or making a SOAP request using the soaplib client returns a Django error page with the error:
Tried hello_world_service in module foo.views. Error was: 'module' object has no attribute 'hello_world_service'
Obviously urls.py is matching correctly, but according to that django snippet I linked to, there shouldn't be a view hello_world_service.
I feel I am missing the last step and any knowledge would be really helpful.
Thanks, Marcus
According to the snippet you link to, the bottom of your views.py file should contain the following line:
hello_world_service = HelloWorldService()
This maps an instance of the HelloWorldService class onto the name hello_world_service, for use in your urls.py file.
If that line is included, then there will indeed be a view with that name - so the URL Dispatcher should be able to find it.
Hope that does it,
Rob
Related
I'm used to Django and already developed website with a whole Django or with Django API + React.
For a side project, I'm thinking about creating a Django project with 2 apps:
Django API 2) Django Front.
I absolutely want to decouple front/back to be able to reuse the API in the future, and I like the view system from Django.
Is my idea making sense?
Edit 1:
To clarify.
App 1: Django API serving JSON.
App 2: Django App using API calls in the controllers to generate the views.
Edit 2:
I did a proof of concept and it works like a charm.
The only drawback is that I have to use Cookies to store the JWT token and maintain the session state, which is not convenient
it is possible, but completely wrong with idea.
How it possible. Wrong version:
Try to remember, how we can create integrate test for our view. We Should create client and send request to Django to your view-url with args kwargs querystring e.t.c.
In response you have already answer. Try to imagine: part with client - is your Django front, requested part - your backend.
The same works not only in test, you can create request to ask something on the completely other server.
Redis/MemCashed e.t.c. (pattern sender/receiver) Wrong version:
The Front Django speaks with Backend through Third part application. It can be faster.
"Pythonic" version. Right in your case:
You can create Backend Django part like a library with views as interfaces.
Frontend Django part is completely standalone, it import an use interfaces from library, which is your "BackEnd Module".
If you want - you can use "BackEnd Module" everywhere as import, or you can start it as server and ask info per requests.
Completely independent in this case means, you can install "BackEnd Module" without "FrontEnd Module". "FrontEnd Module" can be installed standalone too and it should take from settings, which interfaces should be used as data-source.
I hope, i am right understand your question.
You could definitely separate front and back, remember, django just creates endpoints and consumes them with its own views, you can even use both.
Here is the documentation for django views: https://docs.djangoproject.com/en/4.0/#the-view-layer
You can use a librarie like React as frontend and connect to your api(django app) and use both.
I’m currently building a little Django Project and I’ve got a question. I would like to make an API Call to an external API with a user input. How can I achieve that? Pretty new to Django sorry.
Regards,
You can make an API view in Django to receive the request from the user whos using your system with parameters from request body or header (user input) using API View following this link: Django API View.
You can implicitly take these params from the user and send them to the other system to make an API request using requests in python
for example: Pyhton requests
I have a basic user management project that I'm using off of which to scaffold other projects. It is a Vue CLI 3 front end and Django/Django REST Framework/Django REST Auth back end. The project I'm posting here uses sqllite but it can relatively easily be converted to another db.
Here is the link to the full repo for anyone who is willing to download to try to replicate my issue: https://github.com/JVP3122/user-project
I'm having a very strange problem in that when I log out of the site and then try to log back in directly from the same page it seems that axios is adding the payload to the beginning of the request method.
For example, in the images found in the post I put up in Imgur (https://imgur.com/a/bEsx662) the user name is simply "test" with the password "password", and when I try to log back in after logging out the subsequent login attempt is no longer a POST route, but instead a {}POST route. If I try again, the route becomes a {"USERNAME":"TEST","PASSWORD":"PASSWORD"}POST method.
I've tried looking at the config in the axios request interceptor, looking at the dispatch method in the rest_framework source code, and I can't figure out what is going on or how to solve this. It's a small bug that doesn't take away from the rest of the functionality, but it's a bug nonetheless.
Any help would be appreciated.
Did you try:
setting up new project (npm reinstall, clear npm cache etc..)
using axios.post instead of custom made HTTP object
I don't see anything in the backend that could interrupt the request and customise method as described in the original post.
Hopefully one of these two options above will resolve it.
Responded in your issue axios/axios#1994.
According to this StackOverflow post: DjangoRestFramework - How do I customize the frontend?
it says "Typically you want to put your DjangoRestFramework REST Api in something like /api". I'm not sure what this means, so I did some more browsing.
In this GitHub project: https://github.com/kevinastone/django-api-rest-and-angular there is an /example/ folder and inside the folder there is a folder called /api/ which has api.py and serializers.py. I've never come across a tutorial which ever told me to create an api.py file and to place an /api/ folder inside the app (it looks like the app is called "example" in the GitHub project).
I've watched this tutorial: https://godjango.com/41-start-your-api-django-rest-framework-part-1/ and it seems as if the instructor created an app called "api" which has serializers.py and urls.py. With that said, different tutorials show different things. What's the preferred way of creating a Django app which uses the DjangoRestFramework for a ReSTful API?
My end goal is to create a Django app with DjangoRestFramework and AngularJS on the frontend.
I'm sure you've already figured this out, but for other people that stumble upon this he's including his api as it's own django 'app', just like in the tutorial you mentioned. His file "api.py" is basically, for all intents and purposes, serving as what most tutorials call "views.py". But as it is where he declares the methods for his api, and not the applications views, calling it "api.py" is clear cut and makes sense. Doesn't matter what you call it so long as it's imported and used appropriately. The best way to make a rest framework is to use paths that are reflexive of their use case. 'api/post_images' for instance, would post an image and not post a comment or retrieve a user's profile information.
If you only have one rest api call, you may not be interested in holding your single api method in it's own designated file. But as your application grows the use this convention will prove its value.
I am trying to use HTSQL for one of my Django projects. For that I followed the procedure given HERE for furnishing HTSQL/Django requirements. Then I cloned the HTSQL repository for trying the example/demo in it from HERE. I am testing this on Django v1.4. The default db used in the demo example is sqlite3. In Django python shell, the queries are working fine now as per THIS question. But as demonstrated on HTSQL Website, it has a very powerful frontend to communicate with the database and also generates efficient queries (reference). I am trying to use this particular feature for my Django application which is also demonstrated in the demo/example django app from HTSQL. In the demo app, when I started my local django server and tried to access the following url:
localhost:8000/htsql/
The page loads and when I write the following lines:
/polls_poll
to see the data from the polls_poll table, the RUN button does nothing and so does the more drop down menu. No error, no response, no data fetched from the polls_poll table. Then I noticed that the page wasn't loading properly i.e this trace was generated on the Django server terminal. So basically,
codemirror .js and .css files were throwing HTTP 500 error. For that I searched for the links of the codemirror .css and .js files and provided those links in the index.html of the HTSQL resided in the static folder. Following is its path:
>>> /usr/local/lib/python2.7/dist-packages/htsql/tweak/shell/static
Now the terminal trace has changed to THIS
But still the RUN button does nothing and no data is fetched from the table polls_poll
Am I doing something wrong or missing something??
CodeMirror just changed the download URL for their packages, which broke HTSQL shell. You either need to apply the following patch manually:
https://bitbucket.org/prometheus/htsql/changeset/f551f8996610bb68f2f8530fc6c0dbf6b5c34d90
or you can wait for the next bugfix release of HTSQL, which will be out in a day or two.