I'm using an external app in my django project which makes use of generic views, and I'm not able to figure out which template gets called for the response.
Do you know how to do that without having to dig into the source code of the app?
May be debugging the stack trace when the template gets loaded?
The Django debug toolbar will tell you.
Use debug-toolbar when you view a page it will show you the templates used.
Related
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 followed all 42 tutorials on the Try Django Youtube channel, and I'm trying to customize that project to make my own custom app.
My web app only needs two pages for now. One for users (which I only create in the admin) to log in, and another page to use the app. I'm trying to get the hang of the Django dev steps. Correct me if I'm wrong, so if I want to make a single page in a Django web app, I need to set it up in my urls.py, views.py, and make a template html file for it, right?
If I'm getting this order wrong or leaving anything out, any help or advice is appreciated. Can this pattern be found on Django documentation website, too?
Django based on MTV (model, view, template) pattern. More about it here http://aijogja.pythonblogs.com/251_aijogja/archive/1433_django_tutorial-create_a_blog-part_6__mvt_model_view_template_section_1-homepage.html
For adding another page, setup route in urls.py (write regexp), add function in views.py (must return httpresponse) and create template.html
I use django for a large project that is new for me and has many templates. Now I was asked to edit a template that I can display in the browser but I don't know where the template is. Is there a way to make django write out which template it is rendering (and possibly which python classes are used)? Similar to what happens at an error where there is lots of information about what is used.
yes definitely, you can use django debug toolbar for this !
I have a django and I wrote some views. I know how to pass my variables to template, but I also has some external modules with their own views, which I wont modify. Please help me understand how can I get one of my object "Menu.objects.all()" exist in all templates? So for example a I have django-registration and i want to have all my menu items appear at top when someone visits not my app url. I mean it will be registration app url, which returns templateresponse (and here I dont have my variable).
You can add variables to context
The cleanest way to do it, is to use a Template Context Processor, which is a hook that will allow you to add things to your context before the template is rendered.
http://www.djangobook.com/en/2.0/chapter09.html
https://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-own-context-processors
Here's an example of Template Context Processors used in the django core:
https://github.com/django/django/blob/master/django/template/context_processors.py
I'm supplying a Django project to a client, who has requested a 'debugging' page that will show useful information.
[UPDATE for clarity: We'd like this page so we can use it for debugging in future: the clients are not very technical and I won't have direct access to their servers. In the event of future issues, it would be very useful if I could check out this page without asking them to edit the Debug setting or do any other server-side fiddling.]
The project will be running in production, so I can't set DEBUG=True.
What I would like is a page similar to the Django debugging page but without any sensitive information in.
I guess I can simply write my own, but does anyone have any ideas? Anything standard in Django I could use?
Thanks!
Googling 'standard Django debugging page'
Isn't as effective as reading the Django source itself.
Look in base.py for code like this
from django.views import debug
That will provide you some hints as to how they do it.
Then you can look at django/views/debug.py for the "technical_404_response" view function. You can use this function in your code, also.
You can use Django Debug Toolbar and enable it only for choosen IPs