0

I have a django test, on an amazon ec2 instance, I see the "It worked!" page,

i have commented the necessary lines to have access to the admin,

but i cannot see the admin page,

I have to configure properly the urls.py to show the view in my app,

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'^$', 'micopiloto.views.home', name='home'),
    url(r'^$', 'portfolio.views.view', name='home'),
    # url(r'^micopiloto/', include('micopiloto.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)),
)

the view for my app is in: /home/ubuntu/djangoProj/micopiloto/portfolio/views.py

but I have an empty views.py [as i just created the app]

so how do I set the urls.py to connect with my app,

do i need some basic code to see the views.py of my app?

and how to load the admin page?

thanks!

6
  • What do you mean by "i cannot see the admin page"? 404 error, exception, something else? Commented Apr 9, 2012 at 7:57
  • hi thanks, i just see the "it worked page", in the root url and in url/admin Commented Apr 9, 2012 at 7:59
  • Have you uncommented admin in INSTALLED_APPS? Commented Apr 9, 2012 at 8:09
  • @DrTyrsa hi yes man, 'django.contrib.admin', on settings.py,, thanks, what could it be? Commented Apr 9, 2012 at 8:12
  • Haven't you solved the admin problem in the other post? Why did you mark an answer as correct? Commented Apr 9, 2012 at 8:24

2 Answers 2

1

Each view (a function in views.py file) in django is related to a url, that is when the url is visited, that view funciton will be called and the output will be shown in the browser.

To create a simple view function, open the views.py file of the app with a text editor, and add this function to it:

from django.http import HttpResponse

def view(request):
    return HttpResponse('Hello World!')

Now you can view your first page by visiting /, and also can see the admin page in /admin.

Note that the function name must be same as the one you enter in the urls.py (here view as in: 'portfolio.view.view').
Also note that if you have a error in your urls.py files (and some other files like settings.py, admin.py, etc.) you cannot see the admin page, here the error what that you referenced a function called portfolio.views.view in urls.py but there was not such function in your views.py file.

Sign up to request clarification or add additional context in comments.

2 Comments

hi thanks, i have placed the hello world code for my view, and tried with portfoloio.view.view in my urls.py but not working, but it gives me another doubt, if the class is called views.py and is inside portfolio should it be portfolio.views.view?? any way is not working ;(
hi , this wasnt the complete solution for my problem, but pointed me in the right direction thanks!, so i can see the hello world now!!, but using : project.app.views.view ... still grappling to show admin, thanks again!
1

You need to make sure you have setup a database, use sqlite for testing purposes:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'site.db',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

You also need to make sure the admin app is in your INSTALLED_APPS:

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

)

Your urls.py is already correct.

Finally, make sure you syncdb

$ python manage.py syncdb

2 Comments

hi thanks, I have uncomented the admin in installed apps and config the db... what else could it be ;)
Make sure you run the syncdb command, and restart your server (if you aren't using runserver). Make sure you aren't looking at a cached page. CTRL+F5 for example, from your browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.