Can Django be used for web services? - python

My friend said, "Pylons is so much better for web services."
My other friend said, "You can modify Django in a way to do exactly whatever you like."
In Django, what is necessary to be modified (urls.py? models classes? settings?) in order to do "web services" with APIs and REST and versioning, etc etc.?

Yes Django can be used for web services. Check out django-piston:
A mini-framework for Django for
creating RESTful APIs.
Piston is a relatively small Django
application that lets you create
application programming interfaces
(API) for your sites.

Yes, we use it directly. We have view functions that respond to some URI's with serialized JSON or XML objects instead of pretty HTML pages.

Absolutely.
Django is in fact made to be used on server side. But first you need to understand that it is a framework.
A framework is a set of tools which get the common activities done in web development (e.g Login or Sign up module).

Related

Should I implement the django rest framework above django?

Currently i have a Django blog website. (Fully functional)
This blogwebsite is something like a social media website...
I have read that django rest framework helps you to serialize your data.
Could I just check about the DRF:
Is serializing data important? Meaning to say what huge benefits would I get by having an additional django rest framework, and also any possible disadvantages?
Would it be very difficult to "add" the framework into my project. Eg does it require me to download a lot of things and change a lot of my codes?
Where does DRF stand, is it in the backend of frontend or is it more of like in the middle. How does it integrate into my current IT architecture: with django as backend, htmlcssjs as frontend and postgresql as database
Thank you!
Also if anyone is kind enough to share resources about DRF/ open to a short zoom sharing session on DRF, please feel free to contact at kimjoowon777#gmail.com
The idea of Django Rest Framework (DRF) is to simplify and cut down a lot of code from your Backend (aka API).
Django (standalone Django, not DRF) is a framework that allows you to build Backend (and also Frontend).
DRF is a cool library that allows you to create a backend with Django but a lot easier.
DRF allows you to create endpoints that allow you to manipulate the Data (ie. models) very quickly and with very little code.
The "Serialization part" of DRF just automatically (also magically) transforms your models data into a response (usually json) for the client and vice versa.
It does take some learning and coding to transform your current backend into DRF. but in my opinion unless you backend is really special, DRF can allow you to create an awesome API with very little code

What Are The Advantages of Building a Web-Page with Django as Opposed to Solely Using HTML5/CSS3?

Essentially, my questions are as stated above in the title. What I'm really seeking to know is why it would be privy of me to build a web-page utilizing the Django framework as opposed to solely building it out with HTML5 and CSS3.
I do know that Django utilizes bootstrapping of HTML5 and CSS and this is where my questions are raised over the efficiency of using the Django framework as opposed to solely using HTML5/CSS3.
1.) What are the advantages of Django?
2.) What does utilizing the Django framework offer me that HTML5/CSS3 do not?
3.) HTML5 can also build dynamic web-pages as can Django. Why would Django be better for a dynamic web-page?
I am looking for a very valid answer here as I am about to start building my web-page. The responses I get to these questions will be the nail in the coffin for which method I will be using to build the web-page. Thanks ladies and gentleman and I hope you find this question to be worth your while in answering.
Django is a server side framework. So it has little to do with HTML.
Django will give you easier/standardized ways to handle HTTP requests, and to manipulate entries in the database, among other things.
HTML5 alone doesn't enable dynamic web-pages. You can have interactive web pages, but they will always be the same, for every user, whenever you access it.
Django is a python web application framework that allows you to send requests from your page to a server that will in turn provide a response back to your web page.
Advantages: The power of Django is the ability to quickly get both the client ( your page ) and the backend ( the server-side logic ) setup. The backend can include writing to a database, processing information, retrieving information which is subsequently a response delivered to your web page.
HTML5/CSS3 is markup languages for your web page. You can use a editors like sublime or even notepad ++ if you are building a static web page. Django, like most web app frameworks, are used because of what I've described in #1 ( and many other unlisted reasons ).
HTML5 provides the ability to make dynamic web pages ( using a client side library like JQuery as an embedded script ), Django helps you build web apps. You can write a web page using only HTML5 and JQuery to display list of tv shows that are currently on ABC by listing what is currently playing today, but what about for tomorrow? You need server-side help by creating response that will fetch all shows for tomorrow by calling the ABC API. Take a look at server-side logic and web applications.
In short, there are web pages and web applications. Sounds like to me you are building the former, so Django might be overkill.
1.) What are the advantages of Django?
Server-side scripting without the necessity to use PHP. If you already worked with Python, you don't need to learn another language for you server-side.
2.) What does utilizing the Django framework offer me that HTML5/CSS3 do not?
Hm, deployment to a server, handling user requests and dynamically generated webpages. You mentioned making an intricate website in a comment. I don't know what you mean by that, but a framework will let you do this way faster then without. Especially, if you only rely on client-side JS with static HTML5 and CSS3, I'm fairly certain you will have a hard time achieving your goal.
3.) HTML5 can also build dynamic web-pages as can Django. Why would Django be better for a dynamic web-page?
I'm not really sure you understand what dynamic means. Dynamic means generated from code, as opposed to static, which means served directly from an .html file. Django let's you do both, it's a framework and offers lots of flexibility.
If you want to serve same dish for all visitors to your site, HTML is fine. But if you want to server different dish to different user then you'll need ingredients and a way to churn them. Ingredients can be users, their profile and preferences, location, and other entities users are dealing with. Django is one way to churn all of these together and present (in HTML for example) to users.

Django development

This question isn't related to any programming problem or bug rather it's asked to seek knowledge from django developers. I couldnt find proper info as I'm a novice web dev.
I'm a mobile developer and heard quite alot about django. I have looked it up on the internet and official website, from the looks of it, it looks like a framework that is used for storing and retriving data from the database. What are other uses of this framework?
Can django be used to send and receive data from a mobile device?
Your question is not belongs to this site, btw, yes, Django is one of the most famous web frameworks of python, you can up a server via wsgi (or uwsgi) module and make a rest-api server via rest-api-framework, also create SOA.
It depends on your needs, but I think you can use DRF (Django Rest Framework) to standardize your server.
Django was created by a newspaper that wanted a better way of publishing articles. It is a framework for publishing content in a reliable way, so that different types of articles can have corresponding views.
Since then it has evolved a lot so that it can serve as a back-end for many types of websites. I'd suggest checking the Django tutorial which has a lot of good examples and code samples to run through:
https://docs.djangoproject.com/en/1.9/intro/tutorial01/

Django REST browser interface

I'm writing a set of REST services for a Django project. I've been using django-rest-framework for a while. Because of its limited functionality I had to switch to django-piston which I quite enjoy.
However, django-rest-framework had one really nice feature - it was able to display an admin-like interface for testing the created services from the browser. It's just terrific for debugging purposes. It's very simple: one form is displayed for each HTTP method like "GET", "POST", etc. Along with that a drop-down list of available content types and a text field for putting in the data to be sent.
As I view it, this isn't really a feature in any way directly connected with a particular REST framework. It isn't even necessarily about Django. It could all be achieved just using HTML + JS, or an external website.
My question is: What do you use for manual testing / debugging web services? Could you point me to some HTML snippet or a Django app that would do the described thing?
This may seem obvious, but:
Why not just use Django's testing client (django.test.client.Client)? then instead of manually 'debugging' in your browser, you can write unit tests with expectations and get leverage out of those further down the track.
e.g.
from django.test.client import Client
client = Client()
resp = client.put('/employee/2/', data={'email': 'here#there.com'}, follow=True)
#... etc
As the author of django-rest-framework it'd be great to pick your brains about which bits of functionality could do with fleshing out. :) (obv i've got some thoughts of my own and areas I'm planning to work on, but be really good to get some user perspective)
Your absolutely right about the API browser not being limited to any particular framework. To me that's the big deal with DRF and I'd love to see more API frameworks take a similar approach. One of the supposed benefits of RESTful APIs is that they should be self-describing, and it seems counter-intuitive to me that so many of the Web APIs we build today are not Web browseable.
Oh, and totally agree with jsw re. testing Web APIs in django, I wouldn't use the framework's browsable API to replace automated tests.
I had the same problem and that was eaily solved by logging out of admin page in that project.

I need a good web development framework for Python

I'm a C/C++ developer and I also have experience developing web apps with C#, ASP.NET MVC and fluent nhibernate. I'm looking for non-MS alternatives for web development and I'm really interested in python so I went out after Django but I've been told that Django makes it difficult for me to personalize my HTML (not sure if this is accurate).
What I'm looking for is a Python web development framework that is integrated with an ORM, is able to generate the interfaces BUT provides an easy way for me to customize the interface to create an AJAX intensive app
go for django.
does all you wanted,
has perfect docs and even free book,
partially runs on appengine,
has really large user base,
it is mature:
db sharding, (With model router)
xss protection in forms
memcache,
localisation,
well tested support for unicode,
really easy to learn because of level of it documentation.
I'm using Flask (a very minimal web framework) and SQLAlchemy as my ORM. I'm exceedingly happy with it. Disclaimer: I'm only using this for personal projects at the moment, though I do plan to launch a web app in the next 6 months using this setup.
Various options in Python you can look at -
Django (obviously!)
Pylons
Nagare
Flask
Django is really good. And no your info is not correct, HTML templates are real easy to edit them.
Also this is from a developer of Nagare -
Ajax without to write any Javascript
code or the use of continuations makes
a Web application looks like a desktop
one. In fact we have often found that
developers like you, without prior Web
experiences, can be quicker to get
Nagare because they have nothing to
"unlearn".
I am going deeper into this framework Since you said that your app is AJAX intensive. From what I have heard, Nagare makes it easy to do so...
All these frameworks are really good. Some are really good in some areas, others not. So may be explore them all & see which best suits your purpose.
For Web applications development, we're using Nagare, coming with YUI for AJAX communications.
Having a look to Nagare might be an option.
I'm in agreement with the rest of the answers and think that Django is by-far the best choice as a "complete framework" and I think their template system is second-to-none.
If you are looking to create an ajax intensive application, I'd suggestion checking out django-piston (http://bitbucket.org/jespern/django-piston/wiki/Home). Piston is a REST API framework built on top of Django. I've used it for a number of ajax intensive applications and have found it's workflow to be incredibly clean, quick and flexible.
If you are wanting to go a bit slimmer and lighter-weight though, I'd suggest checking out web.py (http://webpy.org/) or Tornado (http://www.tornadoweb.org/).
I would definitely look into Pylons which is very thoroughly documented and has sql alchemy (one of the best python ORM's) baked in. Plus it's easy to setup and learn.
I currently am working with a framework called restish which is flavor of pylons that (surprise, surprise) puts the focus on sticking to RESTful web design. I don't think it's exactly what you're looking for in that it lacks good documentation and any form of an ORM.
Just A side note I'm pretty sure that Django uses Mako templating which gives you excellent control over the HTML.

Categories