Django admin panel works but main page gives me a 404 - django

I'm brand new to Django and Python. I've only done php.
It took me three tries, but I've almost Django installed correctly. I followed the tutorial on installing it, and it worked. So I enabled the admin, panel, and set up mysql.
The admin panel works, and I've got my static folder so it has all of the css as well. But when I go to the main page I get this 404. (My project is called firstweb) So whenI go into firstweb there is a 404, but firstweb/admin works.
Using the URLconf defined in firstweb.urls, Django tried these URL patterns, in this order:
1. ^admin/
The current URL, firstweb/, didn't match any of these.
And I'm confused by the whole runserver thing. Is that some other little server other than my Apache? Why do I need to start it every time?
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'firstweb.views.home', name='home'),
# url(r'^firstweb/', include('firstweb.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)

It looks like your url conf does not include any url pattern for any other pages accept the admin.
If you want the root url to display a page, uncomment this line
url(r'^$', 'firstweb.views.home', name='home'),
And then make sure that in firstweb/views.py you have a view function called 'home', which I assume is part of the tutorial.

Related

Rewrite URL to exclude Django application name

on my live server, I am trying to remove/rewrite the need to include the application name in the URL, as without it I get a 404. For example:
http://www.example.com/myapp/page.html
to
http://www.example.com/page.html
This is especially tricky since i don't want this to affect the django admin URL which excludes the app name.
This is on Apache Server on Ubuntu on a shared host (A2).
You're root urls.py most likely looks something like this:
"""
Definition of urls for api.
"""
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
urlpatterns = [
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', admin.site.urls),
url(r'^myapp/', include('myapp.urls'))
]
When you just replace r'^myapp/' with r'^' the app will be automatically tried, when there is nothing else before that fits (so it's best to put it to the end of the list)

Django admin login with credentials in URL

I am a newbie in Django. Basically what I am looking for is - I want users to click on a link and login into the admin site. Can the parameters be passed in the URL itself ?
Please help.
You can write your own view on your website that will:
get the credentials from your URL
authentificate the user using authenticate and login functions from django.contrib.auth (see https://docs.djangoproject.com/en/dev/topics/auth/default/#auth-web-requests)
and then redirect your user to the admin URL using django redirect function (see https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#redirect)
Register Your admin panel with django . https://docs.djangoproject.com/en/1.3/intro/tutorial02/#activate-the-admin-site
Change your urls.py like
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'mysite.views.home', name='home'),
# url(r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
Give the href as Click
You are done

why my urls.py does't work with Django

Today when I code my blog with 'Building_a_blog_in_30_mins_with_Django_Screencast',I meet some problems.When I click the title with the article,it can't appear the right page.!
Page not found (404)
Request Method: GET
Using the URLconf defined in myblog.urls, Django tried these URL patterns, in this order:
^$
^(?P<pk>\d+)/$
^admin/
^admin/doc/
The current URL, app/1, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
and it's my urls.py:
url(r'^$',ListView.as_view(queryset=Post.objects.all().order_by("created[:2]template_name=" blog.html")),
url(r'^(?P<pk>\d+)/$',DetailView.as_view( model=Post, template_name="post.html")),
url(r'^admin/', include(admin.site.urls)),
url(r'^admin/doc/', include('django.contrib.admindocs.urls'))
I doesn't konw what is going on with it.Please help,thanks!
You need to add 'app/' in your url.
url(r'^app/(?P<pk>\d+)/$',DetailView.as_view( model=Post, template_name="post.html")),
Or may be you need to define these urls in urls.py of your app (named app ?) and include it in sites main urls.py
url(r'app/', include('app.urls'))

django gets a 404 page when I try to access django-registration

Hello and thank you in advance,
When I installed django-profiles and django-registration. I believe I followed a tutorial correctly on how to configure them:
http://agiliq.com/books/djenofdjango/chapter5.html#reusable-apps
Now when I try to access website.com/accounts I get a 404 page:
Using the URLconf defined in acme_p.urls, Django tried these URL patterns, in this order:
^$
^accounts/
^admin/doc/
^admin/
The current URL, accounts, didn't match any of these.
My urls files look like this:
#acme_p urls - Django Project
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', include('user_prof.urls')),
# Examples:
# url(r'^$', 'acme_p.views.home', name='home'),
# url(r'^acme_p/', include('acme_p.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
user_prof urls.py - Django App one level below project mentioned above
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^login/$', 'auth.views.login_user'),
(r'^accounts/', include('registration.urls')),
# (r'^accounts/', include('registration.backends.default.urls')),
)
Thank you for you help.
dp
(r'^accounts/', include('registration.urls')), should be in the root urls.py not the app urls.py
There is no website.com/account in the configuration, there is only website.com/account/(more) where (more) has the rest of the url that is given to the django-registration module. You could try website.com/account/login/ for example to check if the django-registration module is working.
Also you should just put those on the root urls.py file.

Page Not Found error

Why I get this error?
Page not found (404)
Using the URLconf defined in myproject.urls, Django tried these URL patterns, in this order:
^admin/doc/
^admin/
The current URL, , didn't match any of these.
I just uncomment the related lines in urls.py to enable admin and admindoc. They both work; but when I go to the root domain (e.g. example.com), I get this error.
my urls.py is like this:
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^myproject/', include('myproject.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
)
Thanks in advance...
That's because you don't have a URL defined for the root domain. Check our URLconf: it contains the two lines you listed, which means that you only have URLs defined for example.com/admin and example.com/admin/doc, but not just example.com.