Templates on Django - python

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.

Related

Django single website structure

I want to start a new django project. This will just be a relatively simple website to test django itself. So the way all tutorials structure their project is this:
mysite
mysite
some_app
...
For me it's not very clear what does what. I don't really need any app right now. Could I implement my website without using any app? Should I use an app? What would it be called for a simple website?
Have you read Django doc already?
They have a nice tutorial on how to get started.
As for apps, in Django, you have a project containing one or more app. If you just want to try to build a simple website, your project called mysite will contain only one app.
I think you don't need more than the main mysite, BUT, at the django documents, have a session that says:
If your background is in plain old PHP (with no use of modern
frameworks), you’re probably used to putting code under the Web
server’s document root (in a place such as /var/www). With Django, you
don’t do that. It’s not a good idea to put any of this Python code
within your Web server’s document root, because it risks the
possibility that people may be able to view your code over the Web.
That’s not good for security.
Put your code in some directory outside of the document root, such as
/home/mycode.
This model may have been designed with focus on safety.
Some files in mysite could be used to control things in another apps, so i think that is a 'best pratice' to follow this model.
Font
if u aren't in need of an app you can avoid creating one. just give your view in views.py of your project set the url and u r all set to go.
here the first mysite folder is just an usual folder u can change the name in ur convenience next mysite is your project folder and recommended not to change it and next some_app is the application name(you can name your app anything relevant but in proper convention.)
and follow django documentation and djangogirls tutorial for better understanding.
https://docs.djangoproject.com/en/2.0/
https://tutorial.djangogirls.org/en/

Using custom forms in Django instead of modifying the source files

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

Customizing Example Django App - Django Dev Pattern

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

How do I create site homepage in Django that integrates multiple apps?

So I have been following along with the Django Tutorial and have successfully created multiple "apps" that I now want to start integrating into a holistic website (which in Django seems to be called a project).
So here are my questions:
How do I create a site homepage that is mostly static data (HTML, CSS, and images), but also includes data from some of the models of my projects?
How do I link from this homepage to my apps? So if I have an app called "polls" (as in the demo), would linking to the polls page be as simple as linking to /polls?
I think the general approach is that you also have to add one app which glues all your other apps together. So if you need a special homepage which somehow has to have full or part access to all the other apps you create an app for it and point for example your root url to this app.
Following that (and depending if your other apps share data with each other or not) its really as simple as you said. The polls app could be accessible under /polls as an example, depending on how you configured it in your urlconf etc.

Over-ride default Satchmo email with custom template

I'm using Satchmo for the shop section of a website. I'm trying to override the default 'order_complete' email with my own, but haven't been able to so far. The docs indicate that it should be done in the same way as overriding any other template. So I've created one in my template folder at shop/email/order_complete.html, but it isn't being picked up. Anyone have any ideas?
Just a guess but, is Satchmo listed in installed_apps before your own app? (If so the order_complete template may be being matched before yours is ever reached.)
Try moving your app before Satchmo and see if that solves it.
If you want your template folder to take precedence over the app template folders, you have to set your 'django.template.loaders.filesystem.load_template_source', before the app_directories loader.

Categories