Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

How to deploy the learning site app on a local server?

I want to run this app on a local server and in the end on AWS. Can someone guide me on the steps I can take?

4 Answers

Keith Whatling
Keith Whatling
17,752 Points

Ah the big step.

Look at could 9 then pythonanywhere, pythonanywhere runs on AWS but does all the IT techy stuff for you. I really struggle with gunicorn and all that wsgi nigx what ever its called.

Cloud 9 is just like using workspaces but with more grunt, and a great IDE plus its free!

for your local machine,

python manage.py runserver 0.0.0.0:8000

Thanks Keith! But I am getting an error when moving forward

Thanks Kara .. But when i am running the local server it gives me the error as follows.I am not sure what is going on:

NoReverseMatch at / Reverse for 'views.hello_world' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] Request Method: GET Request URL: http://0.0.0.0:8000/ Django Version: 1.10.dev20151122193214 Exception Type: NoReverseMatch Exception Value:
Reverse for 'views.hello_world' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] Exception Location: /Users/prasanna/Downloads/django/django/core/urlresolvers.py in _reverse_with_prefix, line 454 Python Executable: /usr/bin/python Python Version: 2.7.10 Python Path:
['/Users/prasanna/Desktop/learningsite', '/Users/prasanna/Downloads/django', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages'] Server time: Mon, 23 Nov 2015 11:19:41 -0800

Kenneth Love Help please!

Keith Whatling
Keith Whatling
17,752 Points

Post your code, it looks like there is an error in veiws.hello_world.

My url file is as follows:

from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

from . import views

urlpatterns = [
    url(r'^courses/', include('courses.urls', namespace='courses')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', views.hello_world),
]

urlpatterns += staticfiles_urlpatterns()

And this is the views file

from django.shortcuts import render


def hello_world(request):
    return render(request, 'home.html')

This is the setting file

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&s5%_8r2y$9%pbnph*xy*%v^a_!vc0bmbqz%(+l#pc@k7n2r)+'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'courses',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'learning_site.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['templates',],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'learning_site.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Los_Angeles'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'assets'),
)

And this is the home.html file

{% extends "layout.html" %}

{% block title %}Well hello there!{% endblock %}

{% block content %}
<h1>Welcome!</h1>
{% endblock %}

And finally this is the template file:

{% load static from staticfiles %}

<!doctype html>
<html>
    <head>
        <title>{% block title %}{% endblock %}</title>
        <link rel="stylesheet" href="{% static 'css/layout.css' %}">
    </head>
    <body>
        <div class="site-container">
            <nav>
                <a href="{% url 'views.hello_world' %}">Home</a>
                <a href="{% url 'courses:list' %}">Courses</a>
            </nav>
            {% block content %}{% endblock %}
        </div>
    </body>
</html>

Thanks.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Weird, I don't see anything obviously wrong.

Is that the only error message you get? What if you try to go to one of the courses/ URLs?