简体   繁体   中英

django hello world not showing

I am following a tutorial for django , im hosting my project in a free hosting for testing,

the hosting is working fine with python ,and the django shell for example,

but I cannot see the proper data in my index.html or have acces to the /admin

so I think is a problem with a wrong path?,

so please advice on this noob issue,

this is the folder where I have my files /home/mako34/www/blog

here my code:

I suppose settings is configured correctly for the db as it is creating the sqlite db, and the necessary folders

settings.py

import os
*
* configure connection do db, etc
*

ROOT_URLCONF = 'blog.urls'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(os.path.dirname(__file__),'templates'), # creates a absolute path
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

urls.py

from django.conf.urls.defaults 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'^$', 'blog.views.home', name='home'),
    # url(r'^blog/', include('blog.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    (r'^, 'blog.views.index'), #<------------------- index/root entry
    # Uncomment the next line to enable the admin:
     url(r'^admin/', include(admin.site.urls)),


)

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>My Blog</title>
    </head>

<body>
    <H1>Test Django</H1>
    <div id="content">
    {% block content %}
    {% endblock %}
    </div>
</body>

</html> 

So what im i missing?

so i can see my index html with data [as now it shows the tags {% block content %} {% endblock %} and no data in them

and cannot have acces to http://mako34.alwaysdata.net/blog/admin/

thanks!

Your URLs should look like this:

urlpatterns = patterns('',
     url(r'^admin/', include(admin.site.urls)),
     url(r'^', 'blog.views.index'),
)

Note that the index URL you want to work is now wrapped in a url() call. Also, the index URL now follows the admin URL so that urls referencing /admin are handled by the admin URL, not the catch all index URL you've defined.

URL handlers work on first match. Your url(r'^') matches EVERYTHING, so doesn't give a chance for the admin url to work. You should probably change it to url(r'^$') which will match a 'no-path' URL, not a 'every url'. Note the addition of the $ sign, marking the end of a pattern.

Edit:

Ok, now I understand your problem better. What you're trying to do, is to deploy a django app at a particular server path that requires a prefix in the URL path.

This is what is usually a standard URL:

http://www.example.com/
http://www.example.com/admin/
http://www.example.com/index/

Instead, this is what you're trying to do:

http://www.example.com/myapp/
http://www.example.com/myapp/admin/
http://www.example.com/myapp/index/

Django usually expects your app to be deployed at the root URL, with no path. The path is used to find which internal django app should handle the request.

There are two ways for you to solve your problem. The first, and what I'd consider the correct way, is to use the sites framework as described here .

The other, is to add the prefix to all of your URLs in urlpatterns like so:

urlpatterns = patterns('',
     url(r'^blog/admin/', include(admin.site.urls)),
     url(r'^blog/$', 'blog.views.index'),
)

But you will also need to remember to add your 'blog' prefix to several settings that expect URLs like LOGIN_REDIRECT etc etc.

What you really should do though, is make django work at the URL: mako34.alwaysdata.net and forget the /blog/ altogether, but modifying apache to redirect all requests to mod_wsgi.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM