Where is account login template under mezzanine? - django

I'm trying to look for the login page. I've created a folder registeration/login.html under templates, but it doesn't read my updated file at all.
Secondly, there's a button that says login but takes me to accounts/login page, how do I just forward the url to accounts/login then? and where do i customize the login page? I've tried creating an accounts/loginunder templates, that doesn't work.
urls.py
url('^', include('django.contrib.auth.urls')),

It is always a good idea to check out the source code of the framework when you're looking for the answer. In django.contrib.auth.views.LoginView default template is:
template_name = 'registration/login.html'

{% url 'login' %}
Use to retrieve pages from template (html)

I realize this is very late, but will hopefully be helpful for others facing similar issue.
This is the Mezzanine source code for login page which Mezzanine renders by default.
So, you can do something like
python manage.py collecttemplates -t accounts/account_login.html
to copy the above file to your app template directory, and modify the copied file as per your needs.
Bonus: You can find other account related templates (like sign up, password reset, etc.) here.

Related

How to return a 404 for just Django allauth signup page?

I am rather new to Django and all of the work I have done so far has been with models/views/viewsets.. The site I am working on incorporates Django allauth for authentication. I have successfully edited/styled the login/logout templates, but the page will be accessed by people who are given credentials created in the admin section rather than signing up on their own- so the sign up page is unnecessary. I'd like to just show a 404 page anytime someone lands on the signup page. I have already removed all the links to the signup page from the other templates.
In short- how do I just redirect someone to the Django default page_not_found when they hit /accounts/signup/?
My attempts so far have revolved around editing the URLs.py file to include something like path('account_signup', page_not_found) (after importing it at the top), or some other manipulation of that line. I'm probably missing something really easy, as I have been getting a little frustrated... And I haven't found any stack overflows where someone was desiring a 404 when a user navigated to one of the allauth account pages.
In order to server 404 pages automatically for not found url, create a 404 view and then in main projects urls.py have below code
Read the Official docs
handler404 = 'mysite.views.my_custom_page_not_found_view'
For redirecting use Redirect View in django docs
from django.views.generic.base import RedirectView
url('/accounts/signup/', RedirectView.as_view(url='/', permanent=False),name='index')
Note their is 404 page for developers builts in django, but once you turn debug=False in settings for production apps,it is not visible,
You can simply not use the signup page in your urls.
On the other hand, it is bad practice to use createsuperuser to create users, since by default they will have enough privileges, even to log in to admin and edit things. The right thing to do is to create a user with some method you want, and with the permissions you give them.
This last one will allow you to use a decorator in your signup view that only allows access to that page in case you have an account with a particular privilege, and not any user. There is no point in returning a 404.

How are Django page templates assigned to each page?

I couldn't find this info in the Django docs, but I'm sure it is there, I'm just very new and don't know what terms/etc to search on.
How are Django page templates assigned to each page?
I have a login to a Django site, and also SFTP access to the site. I don't think my Django login is a superuser/full-admin though because the interface seems pretty limited compared to other CMS systems. I can edit pages, posts and the media library, but I don't see anything that says how each page is assigned a template.
For example, I have this file /mysite/templates/pages/index.html
I know that template is being used for the home page because it has all of the content that is specific to the home page on it, and changes I make show up on the home page.
I tried copying that file to test.html, but when I browse to test.html in my browser, I get a 404 error (I also get that error if I go to index.html). So there must be something else that maps a template to a page, but I'll be dambed if I can find it. Will I need more access to the admin area, or can I do something with SFTP? I also have SSH access but wasn't able to follow any of the steps online to create a new superuser account for me, for Django.
Edit: Thanks for both answers, after I work through this I'll accept whichever helped the most. I do not have a views.py file, but I think it might be using an extra module for this routing, I have this in my urls.py file:
urlpatterns = patterns("",
("^admin/", include(admin.site.urls)),
url("^$", "mezzanine.pages.views.page", {"slug": "/"}, name="home"),
("^", include("mezzanine.urls")),
)
Is this "mezzanine" something different which changes the answer (location of views.py or list of views)?
url.py is the file that maps the urls to methods that return rendered templates. In essence you define the url and a method and when someone goes to that url, that method gets called which returns a HTTP response with the rendered template. This map is called urlpatterns. In the following example when someone goes to yourwebsite/blog then in the blog apps, view.py, page method is called, which will use a template and render that with specific information.
urlpatterns = patterns('',
url(r'^blog/$', 'blog.views.page'),
url(r'^blog/page(?P<num>\d+)/$', 'blog.views.page'),
)
Have a look at this link.
https://docs.djangoproject.com/en/dev/topics/http/urls/
Django uses urls.py files to map paths to views. This match is resolved using regular expressions. When a match is found, Django executes the associated view (usually inside views.py). The view is in charge to render the template required for the path (by finding it on the server's hard disk and loading it).
All aforementioned means that there's no direct association between a url path (i.e www.example.com/path/to/page) and a file on the server's hard disk (i.e /server/path/to/page). It's all performed dynamically by Django's engine when a request comes in.
If you want to know which view is gonna be generated for a specific path, follow the regexs at urls.py until you find the path you're looking for. Then open the view for that url and see inside which template it is rendering.
Reading doc's URL Dispatcher is a good point to start learning about this.
Hope this helps!

Django-planet shows empty page, while the admin show data that supposed to be displayed

I'm playing with django-planet with Django 1.6, and after some (minor) adaptions. I uploaded some feeds (and I can see them in Django-admin) and mounted them in url.py like this:
url(r'^feeds/', include('planet.urls'))
but when I navigate to feeds/ or any other url specified in django-planet urls.py :
some examples:
url(r'^blogs/$', "blogs_list", name="planet_blog_list"),
url(r'^feeds/$', "feeds_list", name="planet_feed_list"),
I get a blank and empty page. not an error page. but a blank page. when I look at the request I see the django server returning a 200 status. where are django-planet default pages? When I look at django-planet code the views seem to exists..and else I would get an error page
urls.py doesn't look broken to me, since when I navigate to non existent urls in feeds/ or otherwise I do get the expected error page.
I have 2 suspicions:
django-planet not finding the templates. when I look at the lib structure it seems that views.py is naming views that sit in planet subfolder, but actually planet subfolder is under templates folder.
some missing django-planet and undocumented config in my settings.py
how can I solve this?
What am I missing? I'll be glad for help with this
I even downgraded to Django 1.5 but it didn't solve the problem

django user login view

I want to place a "login" field in every page. I looked some examples about authentication in django and all of them creates a new login page and uses django.contrib.auth.views.login .
However, I want to use some parts of this view. So how can i create a view that uses also django auth ?
p.s.: if it's not clear let me know, cause I'm kinda lost and don't know how to ask =)
At first try take a look here https://bitbucket.org/ubernostrum/django-registration/
It is ready done registration/login solution, you can create some template for login and after this include to your pages using include syntax http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#include

Apache | Django: How to run websites on the back of a base URL?

I've got a base url. http://baseurl.com/
I'm trying to run projects on the back of it. For example
http://baseurl.com/mongoose/
The projects run but the URL don't work properly because they all
reference the base url. So for 'About Me' page it points to
http://baseurl.com/about instead of http://baseurl.com/mongoose/about
Is this something i need to change in django or apache? Is what I'm
trying to do even possible?
Coming from an IIS .net background I know that in IIS you can "Create and application" within a site which essentially does what I'm trying to achieve now with Apache and Django.
Thanks
You shouldn't need to do anything. Apache is supposed to be setting a request header called SCRIPT_NAME, which is your base URL, and all URL reversing takes that into account.
How are you creating these URLs in your templates?
Update
So your problem is with getting the URLs of Flatpages. The issue is that the normal way of calculating URLs dynamically, so that they do take SCRIPT_NAME into account - using the reverse() function or the {% url %} tag - doesn't work with Flatpages, because they are not dispatched via urls.py but via a custom middleware which fires on a 404.
So instead of using that middleware, I would use the urls.py mechanism to dispatch to flatpages. Remove the flatpagemiddleware from your settings.py, and in urls.py at the end of your patterns add this:
url(r'^(?P<url>.*)$', 'django.contrib.flatpages.views.flatpage', name='flatpage'),
Now, in your templates, you can do:
<a href="{% url flatpage page.url %}">
and it should work correctly.
Check any urls.py in the project(s) to see if they expect to be top-level. But if the application outputs links like /something then it's going to mean the root directory. The application should be reversing a view/parameter into a URL, which would allow you to move it around. If you wrote the apps, check out reverse in django.core.urlresolvers