4👍
Break it into three “sections”. The first uses a Python API to manipulate the database. The second interfaces your REST API with your Python API. The third talks web and uses the Python API.
1👍
I would create the web application to serve the API to the mobile client. That is, give the web based application direct access to the database. This will simplify your XML / JSON RESTful resource access.
- [Django]-Reverse for 'api' not found. 'api' is not a valid view function or pattern name with rest-framework
- [Django]-How can I in django , get a session created in php?
- [Django]-Missing staticfiles manifest entry in Django deployment using Heroku
- [Django]-How to implement password change form in Django 1.9
1👍
I would say no, don’t use the API for the HTML version. If you design your Django well, you can end up with less code than using the API for the HTML version. You also get to retain the ability to have a web designer work with the Django templates whenever the boss wants the spelling changed on something.
I’d suggest trying to define a base app for your iPhone app to interface with, and then extend that within a second app for the HTML version. App1
would have all of your models (including business logic), and a views.py
for processing the data to/from the iPhone. Then create App2
which uses App1.models
, but creates its own views.py
. With any luck, you’ll find yourself with the ability to change nothing but the template used to render the output, so you can reuse your views by passing the template as an argument.
For example:
App1.views:
def list(request, template="list.json"):
list = Model.objects.filter(deleted=False).filter(user=request.user)
list.reverse()
## Lots of other logic to work on the list.
return render_to_response(template, {list: list,})
App2.views:
def list(request, template="list.html"):
return App1.views.list(request, template=template)
- [Django]-Docker: gracefully stop django server
- [Django]-Email django from using EmailMultiAlternatives
- [Django]-How to send two variables with html as a JSON in Django?
- [Django]-Model datetime field validation for fields with auto_now
- [Django]-Swagger API documentation
0👍
I think the answer to this question has changed over time. A year ago when asked it was probably still too much hassle to do this, but now I’d definitely say yes – using your API as the basis is the smart thing to do. As Web sites use more HTML5 and Mobile apps get smarter it really makes sense to have all your “UIs” read/writing from the same API layer. This will give you much more flexibility in the future.
- [Django]-Extend Django's ManyToManyField with custom fields
- [Django]-How to use Django QuerySet.union() in ModelAdmin.formfield_for_manytomany()?
- [Django]-UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0
- [Django]-How to import a template tag in the interactive shell?