Upgrading from Django 1.4 to Django 1.7 - will it work?

I have a project that I have created over the past few years and it was launched in Django 1.4. The server running this project needs to be replaced, so I am moving to a new server.

I'm considering taking this opportunity to upgrade my project to Django 1.7. I've been looking through the notes and I know I'll be working on tags url

and some other stuff. But the basic structure of the projects seems to have changed. In my project, the folder settings.py

, static

and files / folders with the extended project urls.py

were in the root of the project. However, in version 1.7 (and probably several versions) it seems that these files / folders are being moved to the application folder in the main project.

For example, my 1.4 project has a project structure:

project folder:
    - urls.py # all other app urls.py files are included in this main urls file
    - static # all static files for the whole project reside here
    - settings.py # project settings
    ./app:
        - urls.py #app specific urls

      

But now it seems that the default project structure has changed to this:

project folder:
    - # there nothing here other than the "manage" script
    ./project:
        - # an 'app' with the same name as the project now holds project wide files
        - urls.py # project wide urls file?
        - settings.py # project wide settings? within this app folder?
        - static # project wide static files to be held here? 

      

So, will I be able to run my project in 1.7 given the new project structure?

+3


source to share


4 answers


In Django, you can create any project structure. This way you will be able to run a project barring any other upgrade issues. One of the best current examples of project structure is PyDanny's Django Cookiecutter.

Aside from the abstract user classes, authentication and migration (and commands like syncdb

/ schemamigration

that come with it), nothing really stands in your upgrade path. Some things have been discounted, but they are well documented and easy to fix. In each release, they have ensured that the upgrade path and backward compatibility are clear and as clear as possible.



I would recommend following guidelines 1.5, 1.6 and 1.7, which changed the way the Django community posts. My favorite resource to learn about them is Two Matching Django . PyDanny is one of the authors. There are two versions, for 1.5 and 1.6, and each of them shifts the main differences between the previous version and how new features have changed the way Django applications are written. By reading both, you can get a clear idea of ​​how to upgrade your app from 1.4 to 1.5 to 1.6. Also, the release notes of each version and the django-cookiecutter are great places to see what has changed and what new best practices are.

+4


source


I want to be clear that this is a distilled version of the answers found in the link provided harshil

above. I am adding it here in case the url breaks in the future as it helped me.

  • ADD A SECRET_KEY

    TO YOURSETTINGS.PY

Changed in Django 1.5, Django now requires every project to have a SECRET_KEY.

  1. CONCEPT OF STATEMENTS AND APPLICATION STATEMENTS IN 1.7:

This is a new concept introduced in version 1.7, where Django maintains a registry of your installed apps, so it makes it easier to manage and introspect all of your apps. The best part I liked about this feature is that it makes subapps easier to manage and also runs the initialization code when each app is ready.

You can read more about this here: https://docs.djangoproject.com/en/1.7/ref/applications/

  1. UPDATING DJANGO TEMP URL TO USE NEW SYNTAX INTRODUCED IN DJANGO 1.5:

If you've used Djangos before {% load url from future %}

, you can skip this step, but if you're not sure, you should now change url tags from {% url view_name args %}

to {% url 'view_name' args %}

.

There is this awesome sed command that you can use to convert all your urls to the new format. You can run this command from your template directory

sed -i -r -e "s#\{% url ([a-zA-Z0-9_.:-]+)#\{% url '\1'#g" *

or to run it recursively, you can run the following:

find . -type f -print0 | xargs -0 sed -i -r -e "s#\{% url ([a-zA-Z0-9_.:-]+)#\{% url '\1'#g"

Credit goes to Enrico for posting this label here .

  1. APP LABORATORS

While migrating from Django 1.4 I had problems where new django migrations (this is the next topic) had problems recognizing which "application this model belongs to". Typically, I would just add app_label to all Meta models and set it to the package (folder) name.

  1. MIGRATION

With Django 1.7 you no longer need to go south as migrations are now built in. The best way to migrate from south

to django migrations is to remove all migration files from your migrations folder (leave there __init__.py

).

Do the following to create all new migrations:



python manage.py makemigrations

and then migrate (if django sees the table already exists then it won't run those migrations)

python manage.py migrate

  1. URLS.PY

You can have the following in all of your urls.py

from django.conf.urls.defaults import patterns, include, url

You will want to replace this with: from django.conf.urls import patterns, include, url

  1. HTTPResponse

If there is any code that manually sets the mimetype of the HttpResponse, you will need to change it to content_type.

HttpResponse({"message": "hello world!"}, mimetype="application/json")

becomes HttpResponse({"message": "hello world!"}, content_type="application/json")

  1. GET_QUERY_SET

The method is get_query_set

deprecated, preferring get_queryset

. Therefore, you will also need to change this if you have previously overridden the method get_query_set

.

  1. CACHING

If you've used ORM caching, for example johnny-cache

, you need to either kill it, quit it, or upgrade to something like django-cachalot

.

  1. PLUGINS:

Don't forget to update all your requirements and plugins. Many older plugins may not be compatible with Django 1.7.

  1. Switching to celery> = 3.1.16
+2


source


Here is a good list of things to consider when upgrading from 1.4 http://labs.seedinvest.com/backend/upgrading-from-django-1-4-to-django-1-7/

+1


source


This article suggests the best way to do it, it's one version step at a time:

It will be clear in this section that you should only update one release at a time. You don't have to go from 1.4 to 1.7 directly. Instead, jump from 1.4 to 1.5 first, then jump to 1.6, and so on. This is consistent with the idea of ​​taking small steps.

cm

http://andrewsforge.com/article/upgrading-django-to-17/part-4-upgrade-strategies/

However, it probably depends on the time at which the project might be "put on hold" when reorganizing it to a newer version, probably means that new features are progressing, etc. must be "withheld". I guess it's all at once, it's a big step, so a lot of work at once, but dividing into small steps (version by version) means shorter tracks, but the overall track will probably be longer.

0


source







All Articles