from datetime import datetime, timedelta
from django.shortcuts import render_to_response
from django.template import RequestContext
import api


def index(request):
    uid = request.COOKIES.get("uid")
    if not uid:
        uid, data = api.create_new_user()
    else:
        data = api.get_saved_cities(uid)

    response = render_to_response(
        "homepage/index.html",
        {"saved_cities": data},
        context_instance=RequestContext(request)
    )

    expires = datetime.utcnow() + timedelta(days=180)
    response.set_cookie("uid", uid, expires=expires)

    return response

from datetime import datetime, timedelta
from django.shortcuts import render_to_response
from django.template import RequestContext
import api


def index(request):
    uid = request.COOKIES.get("uid")
    data = None
    if not uid:
        uid, _ = api.create_new_user()
    else:
        data = api.get_saved_cities(uid)

    response = render_to_response(
        "homepage/index.html",
        {"saved_cities": data},
        context_instance=RequestContext(request)
    )

    expires = datetime.utcnow() + timedelta(days=180)
    response.set_cookie("uid", uid, expires=expires)

    return response

Fix create user in homepage view.
Fix create user in homepage view.

api.create_new_user is returning the newly created user record, so we can't pass that as data to the template.

  from datetime import datetime, timedelta
  from django.shortcuts import render_to_response
  from django.template import RequestContext
  import api
  
  
  def index(request):
      uid = request.COOKIES.get("uid")
+     data = None
      if not uid:
-         uid, data = api.create_new_user()
+         uid, _ = api.create_new_user()
      else:
          data = api.get_saved_cities(uid)
  
      response = render_to_response(
          "homepage/index.html",
          {"saved_cities": data},
          context_instance=RequestContext(request)
      )
  
      expires = datetime.utcnow() + timedelta(days=180)
      response.set_cookie("uid", uid, expires=expires)
  
      return response
  
Fix create user in homepage view.
## Code Before:
from datetime import datetime, timedelta
from django.shortcuts import render_to_response
from django.template import RequestContext
import api


def index(request):
    uid = request.COOKIES.get("uid")
    if not uid:
        uid, data = api.create_new_user()
    else:
        data = api.get_saved_cities(uid)

    response = render_to_response(
        "homepage/index.html",
        {"saved_cities": data},
        context_instance=RequestContext(request)
    )

    expires = datetime.utcnow() + timedelta(days=180)
    response.set_cookie("uid", uid, expires=expires)

    return response

## Instruction:
Fix create user in homepage view.
## Code After:
from datetime import datetime, timedelta
from django.shortcuts import render_to_response
from django.template import RequestContext
import api


def index(request):
    uid = request.COOKIES.get("uid")
    data = None
    if not uid:
        uid, _ = api.create_new_user()
    else:
        data = api.get_saved_cities(uid)

    response = render_to_response(
        "homepage/index.html",
        {"saved_cities": data},
        context_instance=RequestContext(request)
    )

    expires = datetime.utcnow() + timedelta(days=180)
    response.set_cookie("uid", uid, expires=expires)

    return response
