I have been leaning Django so I could use the Django admin form in my GAE application. I have just read that GAE doesn't support the django models so i am thinking that it also does not support the admin form.
So the question is does GAE support any other 'forms' or 'reports' environment or do you have to do everything with html
If you're using CloudSQL, django models are supported, and you'll be fine.
If you're using the HRD, getting the admin pages to work would be more difficult.
django models are not supported. The app engine SDK comes with django-style forms that work with the GAE db.Model fields.
Alternatively, you can use django-nonrel which includes a translation layer that allows django models to be used with GAE. The translation layer has various limitations, most prominently, many-to-many relations aren't support. This breaks the Django permissions module which is used by the admin. I've seen some attempts documented to get around this, but I'm not sure how successful people have been.
Related
I'm looking to setup a REST API server with django, and googling suggests this is best done using the django-rest-framework.
The API will return objects stored in a database, and I would also like to be able to add/modify the objects in the database using the django admin site. However, looking at the django-rest-framework documentaion, I see no reference to the admin site (I did find things about "AdminRenderer", but it looked like this isn't what I want).
Simply, does the django admin site exist for a django-rest-framework project?
Simply use the django admin panel provided by django:
Step 1: create superuser
python manage.py createsuperuser
Step 2: run server
python manage.py runserver
Setp 3: Enter the admin site with the newly created credientials
127.0.0.1:8000/admin
Learn more form official documentation:
https://docs.djangoproject.com/en/3.1/intro/tutorial02/#creating-an-admin-user
you can also use the AdminRenderer of django-rest-framework for CRUD operations for using in this purpose as well.
https://www.django-rest-framework.org/api-guide/renderers/#adminrenderer
I am a total noob with Django, I come from the PHP world and I am used to doing things differently.
I'm building an app and I want to change the way the backend looks, I want to use Bootstrap 4 and add a lot of custom stuff e.g. permission based admin views, and I was wondering what is the best practice, or how do more experienced django devs go about it?
Do they override all the django.contrib.admin templates, or do they build custom templates and login/register next to it, and use the django.contrib.admin only for the superuser?
What is the django way?
Django admin is intended for administration purposes. For all intents and purposes it is a direct interface to your database. While I have seen some people building customer facing interfaces using admin, this is most definitely not the way to make a general Django web application.
You should define views for your models. You can use built-in APIs to login and authenticate users. You should most likely restrict access to admin to internal users only.
As for templates, the modern way of doing things is to dynamically fetch data using an API and do all the UI logic in Javascript. Django can be used very well to provide an API to a frontend. Look into Django REST Framework. The basic idea is to write serializers for your models and have view functions serve the serialized data to the front end.
You could go the old school way and render your pages using templates of course. In that case your views would render templates using data provided by your models.
Yes. The admin pages is actually for administering the webpage. For user login and registration you create the templates. However, if you want your backend to look different then you can tweak the template for the admin page, admin login page as well. And you can also have permission based admin views. It's okay to over ride the defaults as long as you know what you're doing. Hope that helped.
Can I use Django Rest Framework to create an "ordinary" site - like a blog, with templated HTML pages ala "normal" django?
The reason I ask this is that I am building a website (sort of a blog), but for sections of the site, the functionality will be provided by making CALLS to a REST API.
So, my question essentially is this:
Is DRF equivalent to (all the features/functionality of django) + ability to create/use RESTful APIs?
Django Rest Framework is an add-on to Django. It doesn't replace Django; it's just another app. You still create your models via Django, and can use views and templates as normal.
I'm using Django with google app engine. I'm using the google furnished django app engine helper project.
I'm attempting to create a Django modelformset like this:
#MyModel inherits from BaseModel
MyFormSet = modelformset_factory(models.MyModel)
However, it's failing with this error:
'ModelOptions' object has no attribute 'fields'
Apparently modelformset_factory() is expecting MyModel to implement a 'fields' accessor.
Anybody successfully used a modelformset with GAE datastore? Or is this a fundamental incompatibility between Django and GAE?
It is a fundamental incompatibility between Django and GAE, because they do not share the same interface for their models. The django helper does not include a patch for the modelformsets, but django-nonrel probably does, or will eventually.
Since the google team does not spend much time on the django helper any more, you are probably better off looking at django-nonrel http://www.allbuttonspressed.com/projects/django-nonrel unless you want to patch the helper yourself.
Is there a well maintained package available in Python for creating and validating HTML forms? I will deploying it finally on Google Appengine.
You can use Django form validation on GAE storage via db.djangoforms.ModelForm.
To smoothly integrate client-side Dojo functionality with Django server-side web apps, I'd look at dojango, which does work fine with GAE (as well as without). However, dojango (currently at release 0.3.1) does not yet automatically provide client-side validation of Django forms -- that's on the roadmap for the forthcoming release 0.4 of dojango, but I have no idea about the timeframe in which you could expect it.
For client-side validation, check http://plugins.jquery.com/search/node/form+validate;
for server-side, actually ALMOST every web framework (web.py, django, etc.) has its own form generation as well as validation lib for you to use.
AppEngine includes Django's form framework (or a variation thereof), which I find very nice. It also plays well with your ORM (i.e. getting forms for models is very DRY). The only potential problem is the lack of client-side validation.