Let me preface this by saying I'm VERY new to Django and am also having a hard time with some of the documentation. I know that this question has surely been asked and answered a thousand times, but I can't seem to phrase my query properly.
I'm making a project that uses django-registration-redux, and I wanted to customize the template and the forms to accept additional user information. First, I noticed that my changes to the template files weren't having any effect , then I realized that it was using the template files from my Python install location instead of my actual project. I fixed this by setting the templates folder setting, but I also need to modify the registration-redux forms, and can't figure out how to override the default forms with local forms in my application.
You need not change the template settings for your existing project, but you have to make sure you have included 'registration' in the list of your INSTALLED_APPS. In the documentation its mentioned that
You can extend and customize the included templates as needed
Though its not very clear here, django registration redux is built on top of the in built django registration module. What you need to do is build your own custom registration form which is already explained in this answer.
In your case the template that you need to modify/extend is registration/registration_form.html.
Other useful resources that can help you:
http://www.tangowithdjango.com/book17/chapters/login_redux.html
https://www.youtube.com/watch?v=qkFWkOw-ByU
Related
Is it okay to make changes to the django packages?
For instance in my project I have a folder lib/python2.7/site-packages/reversion/
And in here I want to add one method inside of models.py
Is this correct?
Initially I wanted to edit django's admin history page. In some models history change messages are shown in unicode format, but I need it to be string readable. In models.py I used eval function to transfer unicode to python list.
No, this is not a good practice.
In general there is other way to edit the default feature (inheritance, write your own page, etc...).
This is because if you modify the django package this becomes difficult to maintain and update.
But if it is a small project you can try to edit django package.
I'm newbie on web dev and chose Django to start, in my application I need sign up and sign in freatures, searching i've found about django-registration:
Link to repo
The setting file and url are already configured, but I have to make the templates for login - I got some templates for test - but I have no idea where to put it, if I have to create a new app ("... startnewapp registration") or just create a directory for templates somewhere.
Can you help me?
you dont really need an external app for just a registration. it is simply one urlconf and one view.
but the most important thing for you now is to go through the tutorial, because tutorial tells you what to put where exactly.. and this cannot be explained here in 3 lines of text
Especially at the beginning it is very helpful to see an example where to put the things together. I developed a django-skeleton, which basically bootstraps a Django installation and boosts starting a new project. I also created views to use the builtin authentication module of Django for registration and to login: https://github.com/n2o/django-skeleton/
In this case I created a separate login app to modify the views and create my own templates.
This is not the easiest way to modify existing templates, but it fulfills all of my requirements.
I'm building a website using django-all auth for it's authentication and social authentication functions. The forms that come bundled with the app are hardly great to look at and hence I decided to create my own views.
The problem is: How do I create them while ensuring that the backend of Django all auth is still available to me? I've dug into the source code and found that it uses class based views for rendering and performing CRUD operations.
I want to know if I can subclass those views in my own app/views.py and just change their template_name field to my own templates. Any advice would be most helpful.
Thanks.
You can of course subclass the views, as long as you change your URLs to point to the overridden versions. However, there is no need to do this just to use your own templates; Django's template loader is specifically written with this use case in mind. Simply create your own directory inside your templates folder to match the one allauth is using, and create your own template files inside it; Django will find yours first and use them.
Django apps can have own message files, locates in their directories. And, suppose, i have an 2 diffrent apps, that is differently translate similar word. It is clear that when gettext used inside the app it will be translated by app's own message file.
How can i predict which translation will be selected when i'm using {%trans%} tag in the template? Is there order, or priority how django resolves this while rendering template?
If it is application you develop, the best approach to ensure correct translation is being used is by specifying context in template or code. This is fully supported as of Django 1.4.
I want to use Pinax for a small project , but I am confused because I don't if can extend/change the behavior and functional of the provided applications .
Is there any documentation for extending the behavior of the bundled applications ?
example: in registration application ,I want to add custom fields but I am not able to find proper documentation on how to achieve it..( mainly for those which need db changes )
Thanks !
Yes, you can extend the behaviour of the built-in applications. If you are using the pinax basic setup with user accounts and profiles, you will have to add the extra fields you want in apps/profiles/models.py. For a list of field types, see here: https://docs.djangoproject.com/en/1.3/ref/models/fields/
This will create the necessary db fields for you when you run manage.py syncdb. If you have already sync'd the db, however, you will have to manually add the db columns. If you don't have any data you care about in that table, you can always just drop the table and it will recreate it. Django doesn't modify db tables once they are created, even if you change the model.
You will also have to modify the signup form to include these new fields and point your urls.py to the new signup form you created. Copy the form from the site-packages/pinax directory to your project. Don't modify them directly.
If you haven't already, you should check out the Django tutorial here: https://docs.djangoproject.com/en/1.3/intro/tutorial01/
This will give you a good idea of how Django apps are put together and how the different pieces interact, so you can do a better job customizing Pinax to your liking. Make sure you know what models.py, urls.py, views.py, and the templates are doing.