Skip to content

Learning Django and deleting all tables

August 8, 2012

These posts seem to have a theme of two topics per post.  Oh well.  I am begining to learn Django and currently I am very happy with it.  A year or so ago I took an ASP.Net course because I knew it was important for most web development.  I later had dropped the class because ASP just seemed like a total mess.  I am very disastified with how the Web languages have developed.  There are several languages you need to know to get any decent website working and it really doesn’t need to be that way.  There should be one programming language that handles front-end and back-end logic and one language for displaying the website.  Though, I’m no expert in web development. Not by any means.

The front/back-end language would be like any other real programming languages like C/C++, Java, or Python.  You’d be able to create variables, do math, handle client-server communication, data-storage, and anything else you need.  With it, I could store data any way I wanted and have a firm grasp of whats going on in the deepest reaches of my website.  I could also handle that data any way I want.  The language could run on the client or the server.  One problem is that a malicous website could attempt to lockdown a clients computer by running an infinate loop. To counter that, the language could be built so the webbrowser is able to override any program running on the website.  There’d be a lot to it but it seems much better than needed to learn a bunch of different languages and interlink them.

The language for displaying content could be pretty much HTML/CSS.  It takes data and puts it where it needs to be.  It could give data to the front/back-end language and retrieve data when its available.  I’m sure there are flaws in this idea but it could work. If it does work, it could be a huge improvement on websites and web based applications.

Now, I’ve been learning Django and its not like I expected. I thought it would be more like what is above.  It is potentially more complex than ASP.Net but it is fitting my needs much better.  ASP.Net was messy.  There was lots of code that didn’t seem nessessary but I didn’t dare mess with it.  I found myself fighting the language and the IDE tooth and nail to get the smallest feature working.  The class I was taking wasn’t much of a help either.  It was just copy the code in the book and hope you didn’t make a typo.  Django on the otherhand has an incredibly helpful introduction tutorial and the Docs do a great job of explaining what needs to be done. Unfortunately other web resources seem rather out of date and incomplete.  I will be adding my own tips and tricks periodically.

Djangos Admin interface is amasing. It alone is worth getting a Django web app running.  When you follow the tutorial, you’ll setup the inital settings of the site. Create a model which is a custom data structure. Play with that data structure. Then enable the admin interface.  There you automatically get the admin site to manipulate your data structure.  It is so simple and within a few hours you have something you can look at and play with.  Later you go onto creating the actual front-end website.  To get there, you need to manipulate the URL handlers which is dificult and you don’t get anything to look at, but it is impressive.

For now, I am making a test web app that is an Image gallery.  It will have an index that displays projects and each project will have a gallery of images pertaining to that project.  Each image in the gallery can be viewed.  Right now, I am working on having Django automatically making thumbnails of the images.

One problem I have been running into has been that when I add new variables to the Models (custom data structures), the internal SQL table freaks out and kind of crashes the website.  Since I don’t have any data I want to keep I am fine just deleting the SQL tables and rebuilding the data.  It only takes a few seconds to recreate my test data.  In case you are having problems deleting the sql tables, read on.

First thing is first, Django can tell you the Sql commands to delete the tables.  In the terminal, navigate to your django websites root and type in:

python sqlclear yourappname

The terminal will print out each command you need to enter into your databases shell.  I am using Sqlite3.  Now in terminal type in:

python dbshell

This will boot up your databases shell.  Type in the commands sqlclear gave you.  When you are done with that (for sqlite3) type .exit to leave the dbshell.  Now rebuild your database with:

python syncdb

And you are set.


From → Django

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: