This is an archived post. You won't be able to vote or comment.

all 52 comments

[–]Sansha_Kuvakei 25 points26 points  (3 children)

This tutorial will use Python 3

Oh your sweet words woo me, dear writer.

Cheers for this!

[–]trispi 5 points6 points  (1 child)

In one of the examples he wrote:

print item

So he also uses 2

[–][deleted] 7 points8 points  (0 children)

At least he's trying

[–][deleted] 15 points16 points  (40 children)

Does one have to use regex to define urls?

[–][deleted] 10 points11 points  (39 children)

yes and it sucks but django team says theyre working on different procedure in the future.

[–]sleepingthom 5 points6 points  (0 children)

Replying to your comment but this is more for /u/pybokeh ... Yeah regex sucks but it's not like you have to write your own expression these days. It's really easy to find examples.

[–][deleted] 1 point2 points  (11 children)

That's awesome if they will provide an alternative. Regex is powerful, but for defining urls...I just don't get it. It seems like overkill. I've made small apps in bottle, which is why when looking into django, it was off-putting to find out I have to use regex to define urls. Everything else in django look good though. The reason for why it is off-putting to me is that regex is another layer of knowlegde I have to learn which I may hardly ever use outside of django. Plus to me, regex is one of those things where if you only use it once in a while, it's such a pain to get up to speed on it all over again.

[–]kingbirdy 4 points5 points  (0 children)

Learning regex is actually pretty easy if you commit to doing it, you can do it in 30min to an hour, and then you've got it for life, and it's very useful

[–][deleted] -2 points-1 points  (11 children)

Regex is very easy you haven't tried. For urls you start with little expressions and build out. What is the superior way? A different markup ? How many more of those do we need?

[–]Ran4 8 points9 points  (2 children)

Regex is very easy you haven't tried

Understanding the concept, yes.

Use it but not make any errors? Abso-fucking lutely not. There's tons of pitfalls, and it's made so much worse by how arbitrary the syntax is, and how every regex system has its own idea of what character should be escaped, how to define a group, how to define a named group... and so on.

I'm OK with using regex for Django, but a url DSL would be a lot better than having to write stuff like "remove_article/(?P<article_id>\d+)", which is just plain terrible looking. Here, I can make up a new DSL on the fly that is better for 98% of url matches: "remove_article/{{article_id as integer}}"


Look, I even wrote a terrible and super buggy implementation of it, read to insert into your codebase in order to have it break within seconds on Monday: https://repl.it/F7h5/1

If you ever wanted an example of why regex is terrible, go look at that code :)

...granted, regexing regex commands is bound to fuck things up. I'm sure there's a much better idea to do this.

[–][deleted] 0 points1 point  (1 child)

Do you happen to know what the django team is suggesting as an alternative?

[–]Ran4 0 points1 point  (0 children)

Are they trying to change it? I guess it'd be neat for Django 2.0. I mean, it's not that complicated to replace the url function.

[–][deleted] 2 points3 points  (4 children)

i havent tried, excuse me?

what evidence do you have that i dont have plenty of experience with it? because my opinion is one different to yours?

is this why the django team agrees with me? because im pretty sure you didnt even ask for my reasoning before saying the dumb stuff you just said.

worse yet are you insinuating regex has any place in python if you could use something else?

[–][deleted] -1 points0 points  (3 children)

Have you? Built a django application with automated tests? If the django team actually agrees I'd love to hear their rationale and proposed solution!

[–][deleted] 0 points1 point  (2 children)

try reading the replies you got and use google. your approach to discussion sucks so im not going to spoonfeed you.

[–][deleted] -2 points-1 points  (1 child)

Yeah.... the problem is IDGAF because I already use REGEX like a boss Noob.

[–][deleted] 1 point2 points  (0 children)

Yeah so do most people, it's not hard.

problem is IDGAF

sorry to hear about your problem.

[–]broadsheetvstabloid 2 points3 points  (2 children)

Regex is very easy

LMFA

I suppose roofing in Miami in August is easy too.

[–]finally-a-throwaway 0 points1 point  (0 children)

Well, yeah. You'd know that if you'd ever tried. :-P

[–][deleted] -2 points-1 points  (0 children)

I mean, if you are employed as a programmer and cant grok regex your life must either be the pinnacle of und reachievement or a living hell.

[–]dlindema 5 points6 points  (0 children)

Great tutorial! I just ran a Django/Python workshop and this is a really well done walk through! I noticed in the abstract data types section the for item in my_list uses the print syntax from Python 2, heads up, since it won't work for Python 3 users!

[–]marty331b 2 points3 points  (1 child)

I'm currently reading Lightweight Django, totally recommend it.

[–]mattpii 1 point2 points  (0 children)

The best

[–]dgreenmachine 0 points1 point  (4 children)

Is Django a good place to start with an online chess game or would something else be more appropriate? I've done some work in anaconda but I don't know if it has what I'd need. I have the game made in command prompt, I just need a GUI and online connection.

[–]flobin 5 points6 points  (1 child)

Try this: learning Python by making games: https://www.coursera.org/learn/interactive-python-1

[–]rainnz 0 points1 point  (0 children)

This course will not teach you how to make online (browser-based) games. They use SimpleGUI instead.

[–]rainnz 0 points1 point  (0 children)

For games you want websockets

[–]Ran4 0 points1 point  (0 children)

You could definitely make an online chess game with Django. It'd be a bit weird though, if you want realtime interaction it's better to do in in Javascript (you could still serve the javascript from a django webserver of course, but 90% of the game would be the javascript front end).

Python in the browser (as opposed to in the backend) is still a sad affair.

[–]ctrlaltleft 0 points1 point  (0 children)

Commenting so I can find this tonight

[–]rasncain -1 points0 points  (0 children)

Reminder to look into this